Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(new task) Adds waitAll and waitAny as convenience for .and/.or
- Loading branch information
1 parent
fd74340
commit ea4d1c0
Showing
4 changed files
with
65 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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
//---------------------------------------------------------------------- | |||
// | |||
// 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. | |||
// | |||
//---------------------------------------------------------------------- | |||
|
|||
const { of } = require('./_task'); | |||
|
|||
const waitAll = (tasks) => { | |||
if (tasks.length === 0) { | |||
throw new Error('Task.waitAll() requires a non-empty array of tasks.'); | |||
} | |||
|
|||
return tasks.reduce( | |||
(a, b) => a.and(b).map(([xs, x]) => [...xs, x]), | |||
of([]) | |||
) | |||
} | |||
|
|||
module.exports = waitAll; |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
//---------------------------------------------------------------------- | |||
// | |||
// 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. | |||
// | |||
//---------------------------------------------------------------------- | |||
|
|||
|
|||
const waitAny = (tasks) => { | |||
if (tasks.length === 0) { | |||
throw new Error(`Task.waitAny() requires a non-empty array of tasks.`); | |||
} | |||
|
|||
return tasks.reduce((a, b) => a.or(b)); | |||
}; | |||
|
|||
|
|||
module.exports = waitAny; |
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