-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
30 lines (23 loc) · 796 Bytes
/
main.cpp
File metadata and controls
30 lines (23 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <thread>
#include <chrono>
#include "Async.h"
int slowAdd(){
std::cout << "Slowly adding numbers from 1 to 1000:\n";
int count = 0;
for(int i = 1; i <= 1000; ++ i){
count += i;
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
return count;
}
int main(){
std::cout << "Without Async:\n";
int count = slowAdd();
std::cout << "Ideally printed out before slowAdd returns, which should be in about 5 sec\n";
std::cout << "slowAdd returned: " << count << "\n\n";
std::cout << "With Async:\n";
Async<int> countAsync(slowAdd);
std::cout << "Ideally printed out before slowAdd returns, which should be in about 5 sec\n";
std::cout << "slowAdd returned: " << countAsync.wait() << "\n\n";
}