Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Propagate async_context
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa authored and xzyfer committed Mar 17, 2018
1 parent ad00d8b commit 968020e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ int GetResult(sass_context_wrapper* ctx_w, Sass_Context* ctx, bool is_sync = fal

void MakeCallback(uv_work_t* req) {
Nan::HandleScope scope;
Nan::AsyncResource async("sass:MakeCallback");

Nan::TryCatch try_catch;
sass_context_wrapper* ctx_w = static_cast<sass_context_wrapper*>(req->data);
Expand All @@ -245,15 +246,15 @@ void MakeCallback(uv_work_t* req) {

if (status == 0 && ctx_w->success_callback) {
// if no error, do callback(null, result)
ctx_w->success_callback->Call(0, 0);
ctx_w->success_callback->Call(0, 0, &async);
}
else if (ctx_w->error_callback) {
// if error, do callback(error)
const char* err = sass_context_get_error_json(ctx);
v8::Local<v8::Value> argv[] = {
Nan::New<v8::String>(err).ToLocalChecked()
};
ctx_w->error_callback->Call(1, argv);
ctx_w->error_callback->Call(1, argv, &async);
}
if (try_catch.HasCaught()) {
Nan::FatalException(try_catch);
Expand Down
3 changes: 2 additions & 1 deletion src/callback_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void CallbackBridge<T, L>::dispatched_async_uv_callback(uv_async_t *req) {
* post_process_args().
*/
Nan::HandleScope scope;
Nan::AsyncResource async("sass:CallbackBridge");
Nan::TryCatch try_catch;

std::vector<v8::Local<v8::Value>> argv_v8 = bridge->pre_process_args(bridge->argv);
Expand All @@ -159,7 +160,7 @@ void CallbackBridge<T, L>::dispatched_async_uv_callback(uv_async_t *req) {
}
argv_v8.push_back(Nan::New(bridge->wrapper));

bridge->callback->Call(argv_v8.size(), &argv_v8[0]);
bridge->callback->Call(argv_v8.size(), &argv_v8[0], &async);

if (try_catch.HasCaught()) {
Nan::FatalException(try_catch);
Expand Down

0 comments on commit 968020e

Please sign in to comment.