forked from infinit/elle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sleep.hh
54 lines (49 loc) · 1.17 KB
/
sleep.hh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <elle/reactor/asio.hh>
#include <elle/reactor/Operation.hh>
namespace elle
{
namespace reactor
{
/// Sleep is an Operation that does nothing but waiting for a certain
/// duration
///
/// Sleep is, for example, used by Thread::sleep(duration).
///
/// @code{.cc}
///
/// std::time_t start = std::time(NULL);
/// auto sleep = elle::reactor::Sleep{elle::reactor::Scheduler::scheduler(),
/// 2s};
/// sleep.run();
/// std::cout << std::difftime(std::time(NULL), start) << " s";
///
/// // Result: 2 s
///
/// @endcode
class Sleep
: public Operation
{
public:
/// Construct a Sleep.
///
/// @param scheduler The Scheduler to run the Operation.
/// @param d The Duration the Thread must sleep.
Sleep(Scheduler& scheduler, Duration d);
protected:
void
_abort() override;
void
_start() override;
/*----------.
| Printable |
`----------*/
public:
void
print(std::ostream& stream) const override;
private:
Duration _duration;
AsioTimer _timer;
};
}
}