Skip to content

Commit

Permalink
better readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mstdokumaci committed Oct 27, 2016
1 parent d42e530 commit cd5a274
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,60 @@ npm install concurrent-task --save
```

## Usage

Below is an example of 5 tasks with 2 steps to execute for each.

```js
const concurrent('concurrent-task')

// create a task runner with concurrency limit 2
const runner = concurrent(2)

runner.set({
steps: {
step1: {
timeout: 1000,
tryCount: 2,
run (data, resolve, reject) {
return clearTimeout.bind(null, setTimeout(() => {
return data.success.compute() ? resolve() : reject(new Error('some error'))
}, data.seconds * 1000))
}
},
step2: {
timeout: 500,
tryCount: 3,
run (data, resolve, reject) {
return clearTimeout.bind(null, setTimeout(() => {
return data.success.compute() ? resolve() : reject(new Error('some error'))
}, data.seconds * 1000))
}
}
},
tasks: {
task1: { seconds: 0.3, success: true },
task2: { seconds: 0.7, success: true },
task3: { seconds: 0.2, success: false },
task4: { seconds: 1.2, success: false },
task5: { seconds: 0.3, success: true }
}
})

runner
.on('error', (key, error) => {
// one of tasks had an error on one of steps
// key is key of task
})
.on('task-done', key => {
// one of tasks completed all steps with no error
})
.on('complete', () => {
// all the tasks completed all steps
// if any of them had errors
// tryCounts are exhausted

// log runner status
console.log(runner.status())
})
.run()
```

0 comments on commit cd5a274

Please sign in to comment.