Repositorio del curso CCOM4030 el semestre B91 del proyecto kilometro0

async.js 629B

12345678910111213141516171819202122232425262728
  1. var from = require('from')
  2. var through = require('../')
  3. var tape = require('tape')
  4. tape('simple async example', function (t) {
  5. var n = 0, expected = [1,2,3,4,5], actual = []
  6. from(expected)
  7. .pipe(through(function(data) {
  8. this.pause()
  9. n ++
  10. setTimeout(function(){
  11. console.log('pushing data', data)
  12. this.push(data)
  13. this.resume()
  14. }.bind(this), 300)
  15. })).pipe(through(function(data) {
  16. console.log('pushing data second time', data);
  17. this.push(data)
  18. })).on('data', function (d) {
  19. actual.push(d)
  20. }).on('end', function() {
  21. t.deepEqual(actual, expected)
  22. t.end()
  23. })
  24. })