source: trip-planner-front/node_modules/minipass-flush/README.md

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.2 KB
Line 
1# minipass-flush
2
3A Minipass stream that calls a flush function before emitting 'end'
4
5## USAGE
6
7```js
8const Flush = require('minipass-flush')
9cons f = new Flush({
10 flush (cb) {
11 // call the cb when done, or return a promise
12 // the 'end' event will wait for it, along with
13 // close, finish, and prefinish.
14 // call the cb with an error, or return a rejecting
15 // promise to emit 'error' instead of doing the 'end'
16 return rerouteAllEncryptions().then(() => clearAllChannels())
17 },
18 // all other minipass options accepted as well
19})
20
21someDataSource.pipe(f).on('end', () => {
22 // proper flushing has been accomplished
23})
24
25// Or as a subclass implementing a 'flush' method:
26class MyFlush extends Flush {
27 flush (cb) {
28 // old fashioned callback style!
29 rerouteAllEncryptions(er => {
30 if (er)
31 return cb(er)
32 clearAllChannels(er => {
33 if (er)
34 cb(er)
35 cb()
36 })
37 })
38 }
39}
40```
41
42That's about it.
43
44If your `flush` method doesn't have to do anything asynchronous, then it's
45better to call the callback right away in this tick, rather than returning
46`Promise.resolve()`, so that the `end` event can happen as soon as
47possible.
Note: See TracBrowser for help on using the repository browser.