Skip to content

Commit 4e386a4

Browse files
committed
Verup 0.9.3, update README
1 parent 605e806 commit 4e386a4

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

README.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Node.js transform stream working at constant pace and concurrent for object mode
1010

1111
## Features
1212

13-
* Specify work time at once (opts.workMS)
14-
* Specify concurrent workers (opts.concurrency)
15-
* Fire `done` event after when all workers have finished asynchrous -processes
13+
* Work time at once can be specified. (workMS option)
14+
* Concurrent workers can be specified. (concurrency option)
15+
* Fires `done` event after when all workers have finished asynchrous -processes
1616
* Counting tag system to call `this.countTag(<tag>)` in `_workPromise`, you can get summarized results `tagCounts` grouped by tag.
1717
* Node.js 4.3 or later
1818

1919
## Targets
2020

21-
* API client needs to handle the rate-limit
22-
* DB client needs to handle the read/write capacity units like AWS DynamoDB
21+
* API client that needs to handle the rate-limit
22+
* DB client that needs to handle the read/write capacity units like AWS DynamoDB
2323

2424
## Install
2525

@@ -29,16 +29,36 @@ $ npm install -save paced-work-stream
2929

3030
## How to Use
3131

32-
### Creating a PacedWorkStream
32+
### Create a PacedWorkStream
33+
34+
**new PacedWorkStream(options, workPromise)**
35+
36+
* `options` `<Object>`
37+
* `concurrency` is the number of concurrent processes.
38+
* `workMS` is milliseconds of work time at once that contains process-time and wait-time.
39+
* `highWaterMark` is maximum object buffer size. If you use flow mode, you should set it at least concurrency.
40+
* `workPromise` is `function(item):` must return a _Promise_ processing the _item_ or a _Function_ that returns a _Promise_.
41+
42+
### Create subclass that extends PacedWorkStream
43+
44+
* `super(options)` must be called in the constructor.
45+
* `_workPromise` method must be overrided and return a _Promise_ processing the _item_ or a _Function_ that returns a _Promise_.
3346

3447
```
35-
new PacedWorkStream(opts, workPromise);
48+
class MyWorkStream extends PacedWorkStream {
49+
constructor(options) {
50+
super(options);
51+
}
52+
_workPromise(item) {
53+
return () => {
54+
this.countTag(item.tag);
55+
return Promise.resolve(item.value);
56+
};
57+
}
58+
}
3659
```
3760

38-
* `opts.concurrency` is the number of concurrent processes.
39-
* `opts.workMS` is milliseconds of work time at once that contains process-time and wait-time.
40-
* `opts.highWaterMark` is maximum object buffer size. If you use flow mode, you should set it the number of source items.
41-
* `workPromise` is `function(item)` must returns a promise processing the item.
61+
## Examples
4262

4363
```javascript
4464
const es = require('event-stream');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "paced-work-stream",
3-
"version": "0.9.2",
3+
"version": "0.9.3",
44
"description": "Node.js stream working at constant pace and concurrent",
55
"main": "lib/main.js",
66
"scripts": {

0 commit comments

Comments
 (0)