Files: 97eb203c6049b5a49935be9ffca99fe8fbd07188 / lib / progress-stream.js
771 bytesRaw
1 | var Pushable = require('pull-pushable') |
2 | var deepEqual = require('deep-equal') |
3 | |
4 | exports.name = 'progressStream' |
5 | exports.version = require('../package.json').version |
6 | exports.manifest = { |
7 | read: 'source' |
8 | } |
9 | |
10 | exports.init = function (ssb, config) { |
11 | return { |
12 | read: function (opts) { |
13 | var lastValue = deepClone(ssb.progress()) |
14 | |
15 | var timer = setInterval(() => { |
16 | var newValue = ssb.progress() |
17 | if (!deepEqual(newValue, lastValue)) { |
18 | lastValue = deepClone(newValue) |
19 | pushable.push(lastValue) |
20 | } |
21 | }, 200) |
22 | |
23 | var pushable = Pushable(() => { |
24 | clearInterval(timer) |
25 | }) |
26 | |
27 | pushable.push(lastValue) |
28 | return pushable |
29 | } |
30 | } |
31 | } |
32 | |
33 | function deepClone (obj) { |
34 | return JSON.parse(JSON.stringify(obj)) |
35 | } |
36 |
Built with git-ssb-web