Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
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
})
29
30