Skip to content

How to use AsyncLocalStorage #2238

Answered by phoenix741
phoenix741 asked this question in Q&A
Discussion options

You must be logged in to vote

To answer to my question, this code works. If i call call_threadsafe_function and then the callback is called then the stacktrace and local storage is keep.

In my case, i made an error. The init function with the callback is called at program start (with callback registered for future use). The callback is called (in async local storage run) by another thread, but is owned by init not by the process that call it.

To have local storage it's not who call the callback but who create the callback that is important.

So i need to fix my program..

#[napi]
pub fn call_threadsafe_function(callback: JsFunction) -> Result<()> {
  let tsfn: ThreadsafeFunction<u32, ErrorStrategy::CalleeHandled> = call…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Brooooooklyn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant