-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b3a09e
commit 5d520e2
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/source/specs/base/concurrency/regression/task-cancellation-174.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//---------------------------------------------------------------------- | ||
// | ||
// This source file is part of the Folktale project. | ||
// | ||
// Licensed under MIT. See LICENCE for full licence information. | ||
// See CONTRIBUTORS for the list of contributors to the project. | ||
// | ||
//---------------------------------------------------------------------- | ||
|
||
// See https://github.com/origamitower/folktale/issues/174 for details | ||
|
||
const { task } = require('folktale/concurrency/task'); | ||
|
||
it('concurrency Regression: chained tasks are not cancelled if partially settled', (done) => { | ||
const started = []; | ||
const finished = []; | ||
let isCancelled = false; | ||
|
||
const delay = (ms, data) => task(resolver => { | ||
started.push(data); | ||
const timer = setTimeout(() => { | ||
finished.push(data); | ||
if (isCancelled) return; | ||
resolver.resolve(data) | ||
}, ms); | ||
resolver.onCancelled(() => clearTimeout(timer)); | ||
}); | ||
|
||
const chain = delay(100, 'a') | ||
.chain(x => delay(100, 'b')) | ||
.chain(x => delay(100, 'c')); | ||
|
||
const execution = chain.run(); | ||
setTimeout(() => { | ||
isCancelled = true; | ||
execution.cancel() | ||
}, 150); | ||
|
||
execution.listen({ | ||
onCancelled: () => { | ||
if (started.join(',') === 'a,b' && finished.join(',') === 'a') { | ||
done(null); | ||
} else { | ||
done(new Error(`Task was cancelled, but expected a and b to be started, but only a to be finished. | ||
Got ${started.join(', ')} started and ${finished.join(', ')} finished`)); | ||
} | ||
}, | ||
|
||
onResolved: () => { | ||
done(new Error(`Expected task chain to be cancelled, but they were resolved.`)); | ||
}, | ||
|
||
onRejected: () => { | ||
done(new Error(`Expected task chain to be cancelled, but they were rejected.`)); | ||
} | ||
}) | ||
|
||
|
||
}); |