git ssb

0+

Piet / ssb-loomio



Tree: c56ea9814a318dd9a4f26fcf109a217e2d13658b

Files: c56ea9814a318dd9a4f26fcf109a217e2d13658b / test.js

711 bytesRaw
1const pull = require('pull-stream')
2pull.merge = require('pull-merge')
3pull.pMap = require('pull-paramap')
4
5const fastStream = pull.values([1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
6const 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
12pull(
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
22function asyncThing (n, cb) {
23 setTimeout(() => cb(null, n), 1000) // simulate some slow lookup
24}
25
26function comparer (a, b) {
27 // console.log('comparing', a, b)
28 return a < b ? -1 : 1
29}
30

Built with git-ssb-web