minipass-flush
A Minipass stream that calls a flush function before emitting 'end'
USAGE
const Flush = require('minipass-flush')
cons f = new Flush({
flush (cb) {
return rerouteAllEncryptions().then(() => clearAllChannels())
},
})
someDataSource.pipe(f).on('end', () => {
})
class MyFlush extends Flush {
flush (cb) {
rerouteAllEncryptions(er => {
if (er)
return cb(er)
clearAllChannels(er => {
if (er)
cb(er)
cb()
})
})
}
}
That's about it.
If your flush
method doesn't have to do anything asynchronous, then it's
better to call the callback right away in this tick, rather than returning
Promise.resolve()
, so that the end
event can happen as soon as
possible.