Comparing version 0.0.10 to 0.0.11
{ | ||
"name": "jdefer", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/tranvansang/jdefer", |
@@ -11,2 +11,4 @@ # Javascript promise defer library | ||
## Single promise with defer | ||
```typescript | ||
@@ -28,1 +30,38 @@ import makeDefer from 'jdefer' | ||
``` | ||
## Broadcast stream | ||
```typescript | ||
import {makeBroadcastStream} from 'jdefer' | ||
// or | ||
const {makeBroadcastStream} = require('jdefer') | ||
const stream = makeBroadcastStream() | ||
// to listen | ||
const removeListener = stream.listen( | ||
(value) => { | ||
console.log(value) | ||
}, { | ||
onDone() { | ||
console.log('done') | ||
}, | ||
onError(error) { | ||
console.error(error) | ||
}, | ||
}) | ||
// to stop listening | ||
removeListener() | ||
// to broadcast | ||
stream.next('foo') | ||
// to broadcast error | ||
stream.throw(new Error('bar')) | ||
// to broadcast done | ||
stream.done() | ||
// iterate | ||
for await (const value of stream) { | ||
console.log(value) | ||
} | ||
``` |
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
5114
66