@@ -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
4464const es = require (' event-stream' );
0 commit comments