[WIP] tsfn: Add context to [Non]BlockingCall callback#676
Closed
KevinEady wants to merge 1 commit intonodejs:masterfrom
Closed
[WIP] tsfn: Add context to [Non]BlockingCall callback#676KevinEady wants to merge 1 commit intonodejs:masterfrom
KevinEady wants to merge 1 commit intonodejs:masterfrom
Conversation
Contributor
Author
|
I ran into this problem when finishing up the PR and now stuck... Basically, the template <typename DataType, typename Callback>
inline napi_status ThreadSafeFunction::BlockingCall(
DataType* data, Callback callback)and is used something like this: tsfn.BlockingCall(data, [](Napi::Env env, Function cb, DataType* data) { ... })and we want to be able to do this... tsfn.BlockingCall(data, [](Napi::Env env, Function cb, DataType* data, void* context) { ... })Similar to how I modified this template <typename DataType>
class DataCallbackWrapper {
private:
using ContextlessCallback = std::function<void(Env, Function, DataType*)>;
using ContextedCallback = std::function<void(Env, Function, DataType*, void *)>;
ContextlessCallback ctxless;
ContextedCallback ctxfull;
public:
CallbackWrapper(ContextlessCallback arg) : ctxless(arg){};
CallbackWrapper(ContextedCallback arg) : ctxfull(arg){};
void operator()(Napi::Env env, Napi::Function callback, DataType* data, void *context) {
ctxfull ? ctxfull(env, callback, data, context) : ctxless(env, callback, data);
};
};
}It just seems like a lot of wrapping and objects, I don't know if this is the right approach. Hopefully we can discuss in today's NAPI meeting. |
Contributor
Author
|
Closing this in favor of #687 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is WIP, currently missing the overload functionality for
[Non]BlockingCall(DataType*, Callback), to allow the Callback to have either signaturevoid(Napi::Env, Function, DataType*)[existing functionality] orvoid(Napi::Env, Function, DataType*, void*)[new context param]Todo:
[Non]BlockingCallwith DataType* overloadsFixes: #653