Commit 8722445354150e8ebe0adaa754aa875e0cc8edd9
expose .closed property, so can check whether database is closed
Dominic Tarr committed on 6/29/2017, 3:01:17 AMParent: 9a1552566c99ce0139006a43936bf9fd109afa1c
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -18,12 +18,10 @@ | ||
18 | 18 … | |
19 | 19 … | module.exports = function (log, isReady) { |
20 | 20 … | var views = [] |
21 | 21 … | var meta = {} |
22 | - var closed = false | |
23 | 22 … | |
24 | 23 … | log.get = count(log.get, 'get') |
25 | -// log.stream = count(log.stream, 'stream') | |
26 | 24 … | |
27 | 25 … | function count (fn, name) { |
28 | 26 … | meta[name] = meta[name] || 0 |
29 | 27 … | return function (a, b) { |
@@ -34,8 +32,9 @@ | ||
34 | 32 … | |
35 | 33 … | var ready = Obv() |
36 | 34 … | ready.set(isReady !== undefined ? isReady : true) |
37 | 35 … | var flume = { |
36 … | + closed: false, | |
38 | 37 … | dir: log.filename ? path.dirname(log.filename) : null, |
39 | 38 … | //stream from the log |
40 | 39 … | since: log.since, |
41 | 40 … | ready: ready, |
@@ -66,9 +65,9 @@ | ||
66 | 65 … | sv.since.once(function (upto) { |
67 | 66 … | pull( |
68 | 67 … | log.stream({gt: upto, live: true, seqs: true, values: true}), |
69 | 68 … | sv.createSink(function (err) { |
70 | - if(err && !closed) console.error(err) | |
69 … | + if(err && !flume.closed) console.error(err) | |
71 | 70 … | }) |
72 | 71 … | ) |
73 | 72 … | }) |
74 | 73 … | |
@@ -96,10 +95,10 @@ | ||
96 | 95 … | //then restream each streamview, and callback when it's uptodate with the main log. |
97 | 96 … | }) |
98 | 97 … | }, |
99 | 98 … | close: function (cb) { |
100 | - if(closed) throw new Error('already closed') | |
101 | - closed = true | |
99 … | + if(flume.closed) throw new Error('already closed') | |
100 … | + flume.closed = true | |
102 | 101 … | cont.para(map(views, function (sv, k) { |
103 | 102 … | return function (cb) { |
104 | 103 … | if(sv.close) sv.close(cb) |
105 | 104 … | else cb() |
@@ -117,4 +116,6 @@ | ||
117 | 116 … | |
118 | 117 … | |
119 | 118 … | |
120 | 119 … | |
120 … | + | |
121 … | + |
Built with git-ssb-web