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
thanks, but what if I need the main script to not use "wait" and wait for a response? and the data from threads came already after sending of all messages in threads?
what if I need the main script to not use await and wait for a response?
I think that you can keep the Promise's returned by th.sendRequest(payload), and later, access each result however you like, e.g.
constresult=[];for(letpayloadof['a','b','c','d']){result.push(th.sendRequest(payload));}setTimeout(()=>{// wait for the thread to finish sending all the messagesresult[2].then(x=>console.log(x));// Cresult[1].then(x=>console.log(x));// Bth.terminate();},8000);
Activity
[-]async/await functions inside ThreadWorker[/-][+]async/await functions inside nodejs ThreadWorker[/+]j-devel commentedon Jan 24, 2023
Yes! I have just added such an example (see https://github.com/w3reality/async-thread-worker/blob/master/examples/node/simple.js).
ser0ja commentedon Jan 24, 2023
thanks, but what if I need the main script to not use "wait" and wait for a response? and the data from threads came already after sending of all messages in threads?
result.push(**await** th.sendRequest(payload));j-devel commentedon Jan 25, 2023
I think that you can keep the
Promise's returned byth.sendRequest(payload), and later, access each result however you like, e.g.