@graffy/stream
Advanced tools
Comparing version 0.11.0 to 0.12.0
@@ -5,3 +5,3 @@ { | ||
"author": "aravind (https://github.com/aravindet)", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"main": "dst/index.js", | ||
@@ -8,0 +8,0 @@ "source": "src/index.js", |
@@ -11,2 +11,3 @@ # Graffy Stream | ||
Imagine the event emitter: | ||
```js | ||
@@ -17,2 +18,3 @@ websocket.addEventListener('message', callback); | ||
We would like to feed this stream of messages into an AsyncIterable, so we can do: | ||
```js | ||
@@ -24,2 +26,3 @@ for await (const message of messages) { | ||
``` | ||
and do stuff. We might also want to call `removeEventListener` when we break (or return or throw) out of the loop. | ||
@@ -77,3 +80,3 @@ | ||
eventSource.close(); | ||
} | ||
}; | ||
}); | ||
@@ -91,15 +94,18 @@ ``` | ||
```js | ||
const stream = makeStream(push => { | ||
eventSource.on('event', event => { | ||
const wait = push(event); | ||
if (wait) { | ||
eventSource.pause(); | ||
wait.then(() => eventSource.resume()); | ||
} | ||
}); | ||
const stream = makeStream( | ||
push => { | ||
eventSource.on('event', event => { | ||
const wait = push(event); | ||
if (wait) { | ||
eventSource.pause(); | ||
wait.then(() => eventSource.resume()); | ||
} | ||
}); | ||
return () => eventSource.close(); | ||
}, { highWatermark: 255, lowWatermark: 4 }); | ||
return () => eventSource.close(); | ||
}, | ||
{ highWatermark: 255, lowWatermark: 4 }, | ||
); | ||
``` | ||
If there are more than `highWatermark` unconsumed events, `push()` will return a Promise `wait`. As the consumer catches up and the number of unconsumed events fall below `lowWatermark`, this promise will resolve. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7432
107