git ssb

10+

Matt McKegg / patchwork



Tree: 51ba1df43b9aa356657c6181fe8e6390ac0da846

Files: 51ba1df43b9aa356657c6181fe8e6390ac0da846 / lib / progress-stream.js

771 bytesRaw
1var Pushable = require('pull-pushable')
2var deepEqual = require('deep-equal')
3
4exports.name = 'progressStream'
5exports.version = require('../package.json').version
6exports.manifest = {
7 read: 'source'
8}
9
10exports.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
33function deepClone (obj) {
34 return JSON.parse(JSON.stringify(obj))
35}
36

Built with git-ssb-web