| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,60 @@ | ||
| #ifndef CALLBACK_WRAPPER_H | ||
| #define CALLBACK_WRAPPER_H | ||
|
|
||
| #include <v8.h> | ||
| #include <node.h> | ||
|
|
||
| #include "nan.h" | ||
| #include <nan.h> | ||
| #include <uv.h> | ||
|
|
||
| using namespace v8; | ||
| using namespace node; | ||
|
|
||
| struct CallbackWrapper { | ||
| class CallbackWrapper { | ||
| Nan::Callback* jsCallback; | ||
| void * payload; | ||
|
|
||
| // throttling data, used for callbacks that need to be throttled | ||
| int throttle; // in milliseconds - if > 0, calls to the JS callback will be throttled | ||
| uint64_t lastCallTime; | ||
|
|
||
| public: | ||
| CallbackWrapper() { | ||
| jsCallback = NULL; | ||
| lastCallTime = 0; | ||
| throttle = 0; | ||
| } | ||
|
|
||
| ~CallbackWrapper() { | ||
| SetCallback(NULL); | ||
| } | ||
|
|
||
| bool HasCallback() { | ||
| return jsCallback != NULL; | ||
| } | ||
|
|
||
| Nan::Callback* GetCallback() { | ||
| return jsCallback; | ||
| } | ||
|
|
||
| void SetCallback(Nan::Callback* callback, int throttle = 0) { | ||
| if(jsCallback) { | ||
| delete jsCallback; | ||
| } | ||
| jsCallback = callback; | ||
| this->throttle = throttle; | ||
| } | ||
|
|
||
| bool WillBeThrottled() { | ||
| if(!throttle) { | ||
| return false; | ||
| } | ||
| // throttle if needed | ||
| uint64_t now = uv_hrtime(); | ||
| if(lastCallTime > 0 && now < lastCallTime + throttle * 1000000) { | ||
| // throttled | ||
| return true; | ||
| } else { | ||
| lastCallTime = now; | ||
| return false; | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| #ifndef LOCK_MASTER_H | ||
| #define LOCK_MASTER_H | ||
|
|
||
| #include <git2.h> | ||
|
|
||
| class LockMasterImpl; | ||
|
|
||
| class LockMaster { | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality💯
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.