pause.asynct.js 944 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. var es = require('../')
  2. , it = require('it-is')
  3. , d = require('ubelt')
  4. exports ['gate buffers when shut'] = function (test) {
  5. var hundy = d.map(1,100, d.id)
  6. , gate = es.pause()
  7. , ten = 10
  8. es.connect(
  9. es.readArray(hundy),
  10. es.log('after readArray'),
  11. gate,
  12. //es.log('after gate'),
  13. es.map(function (num, next) {
  14. //stick a map in here to check that gate never emits when open
  15. it(gate.paused).equal(false)
  16. console.log('data', num)
  17. if(!--ten) {
  18. console.log('PAUSE')
  19. gate.pause()//.resume()
  20. d.delay(gate.resume.bind(gate), 10)()
  21. ten = 10
  22. }
  23. next(null, num)
  24. }),
  25. es.writeArray(function (err, array) { //just realized that I should remove the error param. errors will be emitted
  26. console.log('eonuhoenuoecbulc')
  27. it(array).deepEqual(hundy)
  28. test.done()
  29. })
  30. )
  31. gate.resume()
  32. }
  33. require('./helper')(module)