Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
RunKit + npm: folktale
node v8.17.0
version:
master
endpoint
share
tweet
var { task } = require("folktale@2.2.0-alpha1/concurrency/task") const taskA = task((resolver) => { console.log("executing task A"); resolver.onCancelled(() => { console.log("taskA cancelled"); }); setTimeout(() => { console.log("taskA complete"); if (!resolver.isCancelled) { resolver.resolve("taskA"); } }, 100); }) const taskB = task((resolver) => { console.log("executing task B"); resolver.onCancelled(() => { console.log("taskB cancelled"); }); setTimeout(() => { console.log("taskB complete"); if (!resolver.isCancelled) { resolver.resolve("taskB"); } }, 200); }) const taskC = task((resolver) => { console.log("executing task C"); resolver.onCancelled(() => { console.log("taskC cancelled"); }); setTimeout(() => { console.log("taskC complete"); if (!resolver.isCancelled) { resolver.resolve("taskC"); } }, 300); }) const exec = taskA.chain(() => taskB).chain(() => taskC).run(); setTimeout(() => { console.log("Cancelling task"); exec.cancel(); }, 150); exec.listen({ onCancelled: () => console.log("desired: cancelled task"), onResolved: () => console.log("should not happen: resolved task"), onRejected: () => console.log("should not happen: rejected task") });
Created from: https://npm.runkit.com/folktale
Loading…
no comments
sign in
to comment