Files: 2d88702c84070a0e25dd321ebe69227e78637e7a / sbot / progress.js
649 bytesRaw
1 | var Pushable = require('pull-pushable') |
2 | var deepEqual = require('deep-equal') |
3 | |
4 | module.exports = function (ssb, config) { |
5 | return { |
6 | stream: function (opts) { |
7 | var lastValue = deepClone(ssb.progress()) |
8 | |
9 | var timer = setInterval(() => { |
10 | var newValue = ssb.progress() |
11 | if (!deepEqual(newValue, lastValue)) { |
12 | lastValue = deepClone(newValue) |
13 | pushable.push(lastValue) |
14 | } |
15 | }, 200) |
16 | |
17 | var pushable = Pushable(() => { |
18 | clearInterval(timer) |
19 | }) |
20 | |
21 | pushable.push(lastValue) |
22 | return pushable |
23 | } |
24 | } |
25 | } |
26 | |
27 | function deepClone (obj) { |
28 | return JSON.parse(JSON.stringify(obj)) |
29 | } |
30 |
Built with git-ssb-web