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
I'm doing some p-cancelable testing to get familiar with it and I noticed that isCanceled is not set to true on the promise when the promise is canceled with shouldReject set to false.
I briefly took a look at the library code but TBH I don't see any reason for this to happen so reporting this issue.
My code is (I know, ugly but as said it is my test code):
importPCancelablefrom'p-cancelable';constcancelablePromise=doJob();try{awaitsleep(500);cancelablePromise.cancel();}catch(error){console.log("First main catch error: "+error);}try{constresult=awaitcancelablePromise;console.log("result",result);}catch(error){console.log("Second main catch error: "+error);if(cancelablePromise.isCanceled)console.log("Don't worry it was canceled")}functionsleep(ms){returnnewPromise((resolve)=>{setTimeout(resolve,ms);});}functiondoJob(){returnnewPCancelable((resolve,reject,onCancel)=>{try{consttimeout=setTimeout(()=>{constresult=job();resolve(result);},1000);onCancel.shouldReject=false;onCancel(()=>{console.log('canceled');clearTimeout(timeout);reject(newError('canceled'));});}catch(error){console.log('Promise catch error: '+error);reject(error);}});}
Current behavior:
> node .\index.js
canceled
Second main catch error: Error: canceled
Expected behavior:
> node .\index.js
canceled
Second main catch error: CancelError: Promise was canceled
Don't worry it was canceled
If I remove onCancel.shouldReject = false; then it is fine.
The text was updated successfully, but these errors were encountered:
Ok, I see that it is because there is a reject(new Error('canceled')); line in the onCancel handler which overwrites the state of the promise. But actually, I find it a bit confusing that the promise reports it was not canceled when it actually was.
Maybe the promise should additionally rely on a new internal variable isCanceled rather than only on the state which looks like is overwritable?
Rychu-Pawel
changed the title
isCanceled is not set to true when shouldReject is set to false
isCanceled is not set to true when shouldReject is set to false and promise is rejected in onCancel
Jun 28, 2022
I'm doing some
p-cancelable
testing to get familiar with it and I noticed thatisCanceled
is not set totrue
on the promise when the promise is canceled withshouldReject
set tofalse
.I briefly took a look at the library code but TBH I don't see any reason for this to happen so reporting this issue.
My code is (I know, ugly but as said it is my test code):
Current behavior:
Expected behavior:
If I remove
onCancel.shouldReject = false;
then it is fine.The text was updated successfully, but these errors were encountered: