-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtimer_resource.cpp
More file actions
53 lines (47 loc) · 1.2 KB
/
Copy pathtimer_resource.cpp
File metadata and controls
53 lines (47 loc) · 1.2 KB
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
#include <qtimer.h>
#include "timer_resource.h"
#include "native/global_implement.h"
namespace shelllet {
using namespace global;
}
shelllet::resource::TimerPrivate::TimerPrivate(v8::Isolate* isolate, const v8::Local<v8::Function>& f)
: fn(isolate, f)
{
}
void shelllet::resource::TimerPrivate::setTimeout(const std::function<void(TimerPrivate*)>& cb, uint64_t timeout)
{
timer = std::make_unique<QTimer>();
connection = timer->callOnTimeout([this, cb]() {
cb(this);
});
timer->setSingleShot(true);
timer->setTimerType(Qt::CoarseTimer);
timer->start(timeout);
}
void shelllet::resource::TimerPrivate::clearTimeout()
{
timer->stop();
timer->disconnect(connection);
}
void shelllet::resource::TimerPrivate::setInterval(const std::function<void(TimerPrivate*)>& cb, uint64_t repeat)
{
timer = std::make_unique<QTimer>();
connection = timer->callOnTimeout([this, cb]() {
cb(this);
});
timer->setSingleShot(false);
timer->setInterval(repeat);
timer->setTimerType(Qt::CoarseTimer);
timer->start();
}
void shelllet::resource::TimerPrivate::clearInterval()
{
timer->stop();
timer->disconnect(connection);
}
void shelllet::resource::TimerPrivate::cleanup()
{
clearTimeout();
clearInterval();
fn.Reset();
}