Files: ebb953020ee4430abf945a8a40aeb90b661e3fb0 / test.js
711 bytesRaw
1 | const pull = require('pull-stream') |
2 | pull.merge = require('pull-merge') |
3 | pull.pMap = require('pull-paramap') |
4 | |
5 | const fastStream = pull.values([1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) |
6 | const slowStream = pull( |
7 | pull.values([4, 5, 20, 21, 22, 23, 24, 25, 26, 27]), |
8 | pull.through(n => console.log('pulling ', n)), |
9 | pull.pMap(asyncThing, 2) |
10 | ) |
11 | |
12 | pull( |
13 | pull.merge( |
14 | slowStream, |
15 | fastStream, |
16 | comparer |
17 | ), |
18 | pull.asyncMap((n, cb) => setTimeout(() => cb(null, n), 500)), |
19 | pull.log(() => console.log('DONE')) |
20 | ) |
21 | |
22 | function asyncThing (n, cb) { |
23 | setTimeout(() => cb(null, n), 1000) // simulate some slow lookup |
24 | } |
25 | |
26 | function comparer (a, b) { |
27 | // console.log('comparing', a, b) |
28 | return a < b ? -1 : 1 |
29 | } |
30 |
Built with git-ssb-web