Last active
August 29, 2015 14:16
-
-
Save johnhaley81/8a08813d071a39d5b3a3 to your computer and use it in GitHub Desktop.
`uv_queue_work` error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TransferProgressBaton { | |
const git_transfer_progress * stats; | |
void * payload; | |
uv_work_t req; | |
int result; | |
Persistent<Object> promise; | |
bool done; | |
}; | |
// This is called from a C library. | |
int GitRemoteCallbacks::transfer_progress_cppCallback ( | |
const git_transfer_progress * stats, void * payload ) | |
{ | |
TransferProgressBaton* baton = new TransferProgressBaton(); | |
baton->stats = stats; | |
baton->payload = payload; | |
baton->result = 0; | |
baton->req.data = baton; | |
baton->done = false; | |
// This is randomly causing an error in libuv/src/win/threadpool.c::uv_process_work@79 | |
uv_queue_work(uv_default_loop(), baton->req, transfer_progress_asyncWork, transfer_progress_asyncAfter); | |
while(!baton->done) { | |
this_thread::sleep_for(chrono::milliseconds(1)); | |
} | |
return baton->result; | |
} | |
void GitRemoteCallbacks::transfer_progress_asyncWork(uv_work_t* req) | |
{ | |
// We aren't doing any work on a seperate thread, just need to | |
// access the main node thread in the async after method. | |
// However, this worker method is still needed | |
} | |
void GitRemoteCallbacks::transfer_progress_asyncAfter(uv_work_t* req, int status) | |
{ | |
NanScope(); | |
TransferProgressBaton* baton = static_cast<TransferProgressBaton*>(req->data); | |
GitRemoteCallbacks* instance = static_cast<GitRemoteCallbacks*>(baton->payload); | |
if (instance->transfer_progress->IsEmpty()) { | |
baton->result = 0; // no results acquired | |
baton->done = true; | |
return; | |
} | |
Local<Value> argv[2] = { | |
NanNew(GitTransferProgress::New(&baton->stats, false)), | |
NanNew(instance->payload) | |
}; | |
TryCatch tryCatch; | |
Handle<v8::Value> result = instance->transfer_progress->Call(2, argv); | |
if (result.IsEmpty() || result->IsNativeError()) { | |
baton->result = -1; | |
} else if (!result->IsNull() && !result->IsUndefined()) { | |
if (result->IsNumber()) { | |
baton->result = (int)result->ToNumber()->Value(); | |
} else { | |
baton->result = 0; | |
} | |
} else { | |
baton->result = 0; | |
} | |
baton->done = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment