You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current ThreadsafeFunction API has a major limitation: due to the way it's designed you cannot access the return value of the JS function. That's because the callback API only returns the parameters for the function, and calls the JS function internally, rather than allowing the Rust program to call the JS function directly.
Rather than returning a Vec of arguments to call the function with, I'd like the ThreadSafeCallContext to include the function itself, so that the callback can call the function directly. This would allow the return value to be retrieved, and sent back to the calling thread (e.g. via a channel).
Pseudo code:
let tsfn = callback.create_threadsafe_function(0, |ctx| {let result = ctx.callback.call(None,&[...]);// do something})
For Lightning CSS, I forked threadsafe_function.rs into a version that supports this. You can see the result here. I'd love to upstream this back into napi-rs itself if you are open to the change, but I'm not sure how to do so without breaking changes. I guess it could either be a new API, a mode, a feature flag, or something else. Let me know if any of these would be ok, and I'm happy to send a PR!
The text was updated successfully, but these errors were encountered:
Hey, @devongovett! We are hitting the same limitation on our project. Is your threadsafe_function.rs module used in the production version of Lightning CSS? We are interested in reusing it.
The current ThreadsafeFunction API has a major limitation: due to the way it's designed you cannot access the return value of the JS function. That's because the callback API only returns the parameters for the function, and calls the JS function internally, rather than allowing the Rust program to call the JS function directly.
Rather than returning a
Vec
of arguments to call the function with, I'd like theThreadSafeCallContext
to include the function itself, so that the callback can call the function directly. This would allow the return value to be retrieved, and sent back to the calling thread (e.g. via a channel).Pseudo code:
For Lightning CSS, I forked threadsafe_function.rs into a version that supports this. You can see the result here. I'd love to upstream this back into napi-rs itself if you are open to the change, but I'm not sure how to do so without breaking changes. I guess it could either be a new API, a mode, a feature flag, or something else. Let me know if any of these would be ok, and I'm happy to send a PR!
The text was updated successfully, but these errors were encountered: