example.js 390 B

12345678910111213141516171819202122
  1. var writer = require('./')
  2. var ws = writer(write, flush)
  3. ws.on('finish', function () {
  4. console.log('finished')
  5. })
  6. ws.write('hello')
  7. ws.write('world')
  8. ws.end()
  9. function write (data, enc, cb) {
  10. // i am your normal ._write method
  11. console.log('writing', data.toString())
  12. cb()
  13. }
  14. function flush (cb) {
  15. // i am called before finish is emitted
  16. setTimeout(cb, 1000) // wait 1 sec
  17. }