https://github.com/gadicc/async-composable-tasks
Composable async tasks designed for await/sync and arrow functions, with progress and parallelism.
https://github.com/gadicc/async-composable-tasks
Last synced: about 1 year ago
JSON representation
Composable async tasks designed for await/sync and arrow functions, with progress and parallelism.
- Host: GitHub
- URL: https://github.com/gadicc/async-composable-tasks
- Owner: gadicc
- License: mit
- Created: 2016-04-16T06:39:11.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-05-12T10:54:08.000Z (about 10 years ago)
- Last Synced: 2025-02-17T21:19:04.288Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# async-composable-tasks
Asynchronous, composable tasks built for await/async and arrow functions, with progress and parallelism. Realtime views for React.
[](https://circleci.com/gh/gadicc/async-composable-tasks) [](https://coveralls.io/github/gadicc/async-composable-tasks?branch=master) 
Copyright (c) 2016 Gadi Cohen <dragon@wastelands.net>, released under the MIT license.
## Design Goals
1. Composable - tasks can themselves adds tasks, that are executed in serial or parallel.
1. Async - tasks return Promises that can be used with async/wait.
1. Data - tasks can run a single func with multiple data contexts in parallel.
## Example
```js
var task = new Task();
task.add({
});
task.on('status', ...);
task.run();
```
```
startServer 45/60 [===================== ]
forEachServer 2/3 [========================= ]
downloadDockerImage
```
```js
await new Task(startApp).run(appData);
// We could use inline arrow functions, but declaring our functions just once
// in the root scope is more efficient, and Task() makes use of the function
// name. This convention is better for commonly run functions.
function startApp(task, appData) {
const servers = await db.fetch(...);
// servers is an array, so this will run startServer() with each of the
// values in the array in parallel.
task.add(startServer, servers);
// this task will only be run when all the parallel tasks have finished
task.add(updateAppStatus, appData);
}
function startServer(task, data) {
task.add(downloadDockerImage, data);
task.add(buildDockerContainer, data);
task.add(launchContainer, data);
}
```
what about cases where we want stuff run in parallel and want another task to depend on a previous instance? as opposed to currently where we can run a single task multiple times in parallel, wait for all of those to finish, and then move on.
e.g. wasn't relevant, so far no need for this.
TODO
run taskA after taskB
run taskC after taskB in parallel
i.e. on taskB complete check children for 'after' field