-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(block): added blockCommit, blockJobInfo, and blockJobAbort
- Loading branch information
Showing
7 changed files
with
249 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "worker.h" | ||
|
||
using namespace NLV; | ||
|
||
void Worker::Queue(v8::Handle<v8::Value> v8_callback, ExecuteHandler handler) { | ||
if(!v8_callback->IsFunction()) { | ||
Nan::ThrowTypeError("you must specify a function as the callback");; | ||
return; | ||
} | ||
Nan::Callback *callback = new Nan::Callback(v8_callback.As<Function>()); | ||
auto worker = new NLV::Worker(callback, handler); | ||
Nan::AsyncQueueWorker(worker); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include "nlv_async_worker.h" | ||
|
||
namespace NLV { | ||
class Worker : public NLVAsyncWorkerBase { | ||
public: | ||
typedef std::function<void(Nan::Callback*)> OnFinishedHandler; | ||
|
||
typedef std::function<virErrorPtr(OnFinishedHandler)> SetOnFinishedHandler; | ||
|
||
typedef std::function<virErrorPtr(SetOnFinishedHandler)> ExecuteHandler; | ||
|
||
ExecuteHandler execute_handler; | ||
OnFinishedHandler on_finished_handler; | ||
|
||
explicit Worker(Nan::Callback *callback, ExecuteHandler handler) | ||
: NLVAsyncWorkerBase(callback), execute_handler(handler) { }; | ||
|
||
void HandleOKCallback() { | ||
on_finished_handler(callback); | ||
} | ||
|
||
virtual void Execute() { | ||
auto error = execute_handler([=] (OnFinishedHandler handler) { | ||
on_finished_handler = handler; | ||
return nullptr; | ||
}); | ||
if(error) { | ||
SetVirError(error); | ||
} | ||
} | ||
|
||
// TODO: make it a template so that it can accept arbitrary number of arguments | ||
// of objects to make persistent for the duration of the worker run | ||
static void Queue(v8::Handle<v8::Value> v8_callback, ExecuteHandler handler); | ||
}; | ||
|
||
template<class T> | ||
Worker::OnFinishedHandler PrimitiveReturnHandler(T val) { | ||
return [=](Nan::Callback* callback) { | ||
Nan::HandleScope scope; | ||
v8::Local<v8::Value> argv[] = { Nan::Null(), Nan::New(val) }; | ||
callback->Call(2, argv); | ||
}; | ||
} | ||
}; |