-
Notifications
You must be signed in to change notification settings - Fork 462
New issue
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
Add example/api to use ThreadSafeFunction with optional callback param #544
Comments
I think it would make more sense to add a new signature without the |
Sooo I think implementing a new constructor will blow up the number of constructors we have. We currently have thirteen |
I would like to use this issue to highlight all issues with TSFN constructors. I point out the ambiguity between the TSFN::New with struct TestData {
// Native Promise returned to JavaScript
Promise::Deferred deferred;
// List of threads created for test. This list only ever accessed via main
// thread.
vector<thread> threads = {};
ThreadSafeFunction tsfn = ThreadSafeFunction();
};
void FinalizerCallback(Napi::Env env, TestData* finalizeData){
for (size_t i = 0; i < finalizeData->threads.size(); ++i) {
finalizeData->threads[i].join();
}
finalizeData->deferred.Resolve(Boolean::New(env,true));
delete finalizeData;
}
static Value TestAcquire(const CallbackInfo& info) {
// ....
TestData *testData = new TestData({
Promise::Deferred::New(env)
});
testData->tsfn = ThreadSafeFunction::New(env, cb, "Test", 0, 1,
FinalizerCallback, testData);
// ...
} The call to
I can solve this issue by explicitly using testData->tsfn = ThreadSafeFunction::New(env, cb, "Test", 0, 1,
std::function<void (Napi::Env env, TestData* finalizeData)>(FinalizerCallback),
testData); |
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
@KevinEady , @legendecas should do we still need this issue? |
@mhdawson , is it useful to provide an example with the optional callback..? Not sure, because it is as simple as not providing the |
@legendecas what's your take, I don't have a strong opinion one way or the other. |
I may say that this may not be the way ThreadSafeFunction recommended to use. I'm closing since I did not find any strong use case on this. Even cases may arise, documenting that the callback can be empty sounds enough to me. |
Since nodejs/node#27791 has been landed, there might be some use cases on node-addon-api to use
Napi::ThreadSafeFunction
with optional callback parameter.Approaches might be adding an example of how to use existing
Napi::ThreadSafeFunction::New
like:(is there a more intuitive one?)
Or add a new API which make the callback omitted:
The text was updated successfully, but these errors were encountered: