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
So I had an idea to use Abort Controller to stop long running async operations (basically for awaited promises put timeout).
However it seems like it has no effect at all (same as pure NodeJS).
Idea behind this code is to abort long running awaited promises.
constAbortController=require('node-abort-controller');asyncfunctioninit(){asyncfunctionmyLongRunningAsyncTask(timeToDone){returnnewPromise(resolve=>setTimeout(()=>{console.log(`I got my long running task done in ${timeToDone}ms!`);resolve(true);},timeToDone));}asyncfunctiontimeout(timeout,controller){returnnewPromise(resolve=>setTimeout(()=>{console.log('Timeout signal');controller.abort();resolve('Timeout');}));}asyncfunctiondoSomethingAsync(promise,signal){if(signal.aborted){returnPromise.reject('Timeout!');}returnnewPromise(async(resolve,reject)=>{signal.addEventListener('abort',()=>{reject('Timeout!');});console.log('--- Promise Started ---');awaitpromise;console.log('--- Promise Ended ---');resolve(promise);});}console.log('Start');constcontroller=newAbortController();constsignal=controller.signal;try{awaitPromise.race([doSomethingAsync(myLongRunningAsyncTask(700),signal),timeout(500,controller)]);}catch(e){console.log(e);}console.log('End');}init();
Sadly is has no effect....
Start
--- Promise Started ---
Timeout signal
Timeout!
End
I got my long running task done in 700ms!
--- Promise Ended ---
The perfection would be that long running async operation is killed when I call abort, however it seems like it is not possible?
The text was updated successfully, but these errors were encountered:
So I had an idea to use Abort Controller to stop long running async operations (basically for awaited promises put timeout).
However it seems like it has no effect at all (same as pure NodeJS).
Idea behind this code is to abort long running awaited promises.
Sadly is has no effect....
The perfection would be that long running async operation is killed when I call abort, however it seems like it is not possible?
The text was updated successfully, but these errors were encountered: