aswi2020vldc-gitlab/templetes/node_modules/flush-write-stream/example.js @ 9bb1e829
1 |
var writer = require('./') |
---|---|
2 |
|
3 |
var ws = writer(write, flush) |
4 |
|
5 |
ws.on('finish', function () { |
6 |
console.log('finished') |
7 |
})
|
8 |
|
9 |
ws.write('hello') |
10 |
ws.write('world') |
11 |
ws.end() |
12 |
|
13 |
function write (data, enc, cb) { |
14 |
// i am your normal ._write method
|
15 |
console.log('writing', data.toString()) |
16 |
cb() |
17 |
}
|
18 |
|
19 |
function flush (cb) { |
20 |
// i am called before finish is emitted
|
21 |
setTimeout(cb, 1000) // wait 1 sec |
22 |
}
|