In ECMAScript I am using CancelablePromise (https://github.com/alkemics/CancelablePromise) that basically is just a Promise with a .cancel()
function. Whenever .cancel()
is called, the callbacks provided to .then()
and .catch()
are not executed.
I wonder what happens if I await on a cancelled promise:
CancelablePromise promise = new CancelablePromise((resolve, reject) => resolve(1));
const promise2 = promise.then(x => x + 1);
promise.cancel();
console.log(await promise2);
So this code works as expected, nothing is printed on console. However, I wonder if this creates any hanging threads / references that cannot be collected by the GC or is this perfectly safe and valid to use?