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
const{ AsyncLocalStorage }=require('node:async_hooks');constasyncLocalStorage=newAsyncLocalStorage();conststore={id: 2};try{asyncLocalStorage.run(store,()=>{conststore1=asyncLocalStorage.getStore();// Returns the store objectconsole.log({ store1 })setTimeout(()=>{conststore2=asyncLocalStorage.getStore();// Returns the store objectconsole.log({ store2 })},200);thrownewError();});}catch(e){conststore3=asyncLocalStorage.getStore();// Returns undefinedconsole.log({ store3 })// The error will be caught here}
The result of this code below
should be this:
but, the actual result from RunJS was this:
The code that I wrote was almost same as that in Nodejs Document:
https://nodejs.org/api/async_context.html#asynclocalstoragerunstore-callback-args
The text was updated successfully, but these errors were encountered: