Skip to content
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

No way to pass user data to thread service callback #6957

Open
zopsicle opened this issue Nov 10, 2023 · 1 comment
Open

No way to pass user data to thread service callback #6957

zopsicle opened this issue Nov 10, 2023 · 1 comment
Labels

Comments

@zopsicle
Copy link

zopsicle commented Nov 10, 2023

Customarily, callbacks take an additional user data parameter so that closures can be used as callbacks. This is the case with, for example, JsMemoryAllocationCallback. However, JsThreadServiceCallback takes no such parameter (do not confuse this with its callbackState parameter, which is not user data rather engine-provided data for the work item callback).

Ideally the API would be:

typedef bool (CALLBACK *JsThreadServiceCallback)(
    _In_ JsBackgroundWorkItemCallback workItemCallback,
    _In_opt_ void *workItemCallbackState,
    _In_opt_ void *threadServiceCallbackState
);

STDAPI_(JsErrorCode) JsCreateRuntime(
    _In_ JsRuntimeAttributes attributes,
    _In_opt_ JsThreadServiceCallback threadService,
    _In_opt_ void *threadServiceCallbackState
    _Out_ JsRuntimeHandle *runtime
);

where the runtime would pass threadServiceCallbackState to threadService whenever it’s called.

@rhuanjl rhuanjl added the APIs label Apr 22, 2024
@rhuanjl
Copy link
Collaborator

rhuanjl commented Apr 22, 2024

I wouldn't want to break the existing JsCreateRuntime, so to implement this would involve either:
a) Making the existing function somehow able to accept either just a callback OR a struct that points to both the "state" and the callback - with some way of checking which it was receiving (maybe via an attribute?)
OR
b) Making an additional API for if people want a state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants