-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy pathdeferrer.cc
More file actions
35 lines (27 loc) · 806 Bytes
/
Copy pathdeferrer.cc
File metadata and controls
35 lines (27 loc) · 806 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
33
34
35
#include "src/node/deferrer.hh"
#include <node_api.h>
namespace node_webrtc {
Deferrer::Deferrer(Napi::Env env) : _env(env) {
napi_create_async_work(_env, nullptr, Napi::String::New(env, "Deferrer"),
&Deferrer::DoNothing, &Deferrer::CallExecute, this,
&_work);
}
Deferrer::~Deferrer() {
napi_delete_async_work(_env, _work);
_work = nullptr;
}
void Deferrer::Queue() {
if (_work_mutex.try_lock()) {
Napi::HandleScope scope(_env);
napi_queue_async_work(_env, _work);
}
}
void Deferrer::DoNothing(napi_env, void *) {
// Do nothing.
}
void Deferrer::CallExecute(napi_env, napi_status, void *data) {
auto self = static_cast<Deferrer *>(data);
self->_work_mutex.unlock();
self->Execute(self->_env);
}
} // namespace node_webrtc