Cancels a task execution. Does nothing if the task has already been resolved.
Cancels a task execution. Does nothing if the task has already been resolved.
const { task } = require('folktale/concurrency/task');
let message = 'world';
const helloIn50 = task(
resolver => {
const timerId = setTimeout(() => {
message = 'hello';
resolver.resolve();
}, 50);
resolver.cleanup(() => clearTimeout(timerId));
}
);
const execution = helloIn50.run();
execution.cancel();
try {
const result = await execution.promise();
throw 'never happens';
} catch (error) {
$ASSERT(message == 'world');
}