| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | var from = require('from') |
| 2 | var through = require('../') |
| 3 | |
| 4 | var tape = require('tape') |
| 5 | |
| 6 | tape('simple async example', function (t) { |
| 7 | |
| 8 | var n = 0, expected = [1,2,3,4,5], actual = [] |
| 9 | from(expected) |
| 10 | .pipe(through(function(data) { |
| 11 | this.pause() |
| 12 | n ++ |
| 13 | setTimeout(function(){ |
| 14 | console.log('pushing data', data) |
| 15 | this.push(data) |
| 16 | this.resume() |
| 17 | }.bind(this), 300) |
| 18 | })).pipe(through(function(data) { |
| 19 | console.log('pushing data second time', data); |
| 20 | this.push(data) |
| 21 | })).on('data', function (d) { |
| 22 | actual.push(d) |
| 23 | }).on('end', function() { |
| 24 | t.deepEqual(actual, expected) |
| 25 | t.end() |
| 26 | }) |
| 27 | |
| 28 | }) |