-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
32 lines (26 loc) · 843 Bytes
/
Copy pathtimer.cpp
File metadata and controls
32 lines (26 loc) · 843 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
31
32
/*
* The [Timer][] type from the [time][] package is implemented. This type was
* implemented in order to build the context classes. Timers operate by
* spawning a thread that waits on a condition variable. If the condition is
* notified (via `bongo::timer::stop()`) the timer is canceled, otherwise it
* times out.
*
* [Timer]: https://golang.org/pkg/time/#Timer
* [time]: https://golang.org/pkg/time/
*/
#include <chrono>
#include <iostream>
#include <bongo/time.h>
using namespace std::chrono_literals;
int main() try {
bongo::time::timer t{5s};
decltype(t)::recv_type v;
v << t.c();
std::cout << "Timed out after "
<< std::chrono::duration_cast<std::chrono::seconds>(*v).count()
<< " seconds.\n";
return 0;
} catch (std::exception const& e) {
std::cerr << e.what() << "\n";
return 1;
}