Skip to content

Commit 2452c40

Browse files
committed
Allow waitForResult to be specified
1 parent 74a7e07 commit 2452c40

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

generate/templates/manual/include/callback_wrapper.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class CallbackWrapper {
1414
int throttle; // in milliseconds - if > 0, calls to the JS callback will be throttled
1515
uint64_t lastCallTime;
1616

17+
// false will trigger the callback and not wait for the callback to finish
18+
// in this case, the underlying libgit2 function will immediately be given
19+
// the default result
20+
bool waitForResult;
21+
1722
public:
1823
CallbackWrapper() {
1924
jsCallback = NULL;
@@ -33,12 +38,17 @@ class CallbackWrapper {
3338
return jsCallback;
3439
}
3540

36-
void SetCallback(Nan::Callback* callback, int throttle = 0) {
41+
void SetCallback(Nan::Callback* callback, int throttle = 0, bool waitForResult = true) {
3742
if(jsCallback) {
3843
delete jsCallback;
3944
}
4045
jsCallback = callback;
4146
this->throttle = throttle;
47+
this->waitForResult = waitForResult;
48+
}
49+
50+
bool ShouldWaitForResult() {
51+
return waitForResult;
4252
}
4353

4454
bool WillBeThrottled() {

generate/templates/partials/field_accessors.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
{% elsif field.isCallbackFunction %}
4949
Nan::Callback *callback = NULL;
5050
int throttle = {%if field.return.throttle %}{{ field.return.throttle }}{%else%}0{%endif%};
51+
bool waitForResult = true;
5152

5253
if (value->IsFunction()) {
5354
callback = new Nan::Callback(value.As<Function>());
@@ -59,13 +60,20 @@
5960
Local<Value> objectCallback = maybeObjectCallback.ToLocalChecked();
6061
if (objectCallback->IsFunction()) {
6162
callback = new Nan::Callback(objectCallback.As<Function>());
63+
6264
Nan::MaybeLocal<Value> maybeObjectThrottle = Nan::Get(object, Nan::New("throttle").ToLocalChecked());
6365
if(!maybeObjectThrottle.IsEmpty()) {
6466
Local<Value> objectThrottle = maybeObjectThrottle.ToLocalChecked();
6567
if (objectThrottle->IsNumber()) {
6668
throttle = (int)objectThrottle.As<Number>()->Value();
6769
}
6870
}
71+
72+
Nan::MaybeLocal<Value> maybeObjectWaitForResult = Nan::Get(object, Nan::New("waitForResult").ToLocalChecked());
73+
if(!maybeObjectWaitForResult.IsEmpty()) {
74+
Local<Value> objectWaitForResult = maybeObjectWaitForResult.ToLocalChecked();
75+
waitForResult = (bool)objectWaitForResult->BooleanValue();
76+
}
6977
}
7078
}
7179
}
@@ -74,7 +82,7 @@
7482
wrapper->raw->{{ field.name }} = ({{ field.cType }}){{ field.name }}_cppCallback;
7583
}
7684

77-
wrapper->{{ field.name }}.SetCallback(callback, throttle);
85+
wrapper->{{ field.name }}.SetCallback(callback, throttle, waitForResult);
7886
}
7987

8088
{% elsif field.payloadFor %}

0 commit comments

Comments
 (0)