-
-
Notifications
You must be signed in to change notification settings - Fork 587
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
refactor: support new tsfn (stage 1) #5885
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
af940c1
to
59cafdf
Compare
Test Compatibility Diff
Unpassed tests2 ⚪️ aggressive-splitting-entry: TODO |
fc1718f
to
e48663c
Compare
Leaving package change until NAPI released a new version... |
Summary
This PR refactored the old tsfn impl. The original impl has a few problems as follows:
Promise<T>
orT
. This is originally designed for loader, since JS Loaders can be called both synchronously and asynchronously. This usage has been spread to most of JS functions and each signature should be defined explicitly.In this new tsfn impl, the improvements are as follows:
ThreadsafeFunction<(A, B), Either<A, Promise<T>>>
.ThreadsafeFunction<(A, B), ...>
would be converted to the two parameters for JS functions. In this example: it's(a: A, b: B) => ...
FromNapiValue
It's not necessary to convertJSFunction
toThreadsafeFunction
on your own, just apply derive#[napi(object, object_to_js = false)]
and replaceJSFunction
withThreadsafeFunction<T, R>
Promise<T>
, it's up to your choice to either call withcall_with_promise
to resolve to it's original value with error being carefully converted to JS andcall_with_sync
with the originalPromise<T>
being returned. IfEither<T, Promise<T>>
is returned, you may alsocall_with_auto
to extract the valueT
.call
is still provided for you to extract the value behindPromise<T> | T
by calling methodcall
, you may keep the threadsafe function's type signature as-is, such asThreadsafeFunction<(A, B), T>
. This is highly NOT recommended tho.NAPI Refs:
Require Documentation?