git ssb

0+

cel / ssb-issues



Commit 7880a84c53be4a312a09ca7cb7d1ac5bafc76d23

Add deinit method

Charles Lehner committed on 9/20/2016, 1:47:59 AM
Parent: 43d017788d2f57c366a1d4ccb85142ebba4ade90

Files changed

index.jschanged
package.jsonchanged
index.jsView
@@ -1,8 +1,9 @@
11 var pull = require('pull-stream')
22 var paramap = require('pull-paramap')
33 var asyncMemo = require('asyncmemo')
44 var issueSchemas = require('./lib/schemas')
5 +var multicb = require('multicb')
56
67 function Cache(fn, ssb) {
78 return asyncMemo(fn)
89 return function (key, cb) { ac.get(key, cb) }
@@ -58,8 +59,9 @@
5859
5960 exports.init = function (ssb) {
6061
6162 var ssbGet = asyncMemo(ssb.get)
63 + var liveStreams = []
6264
6365 var getIssue = asyncMemo(function (id, cb) {
6466 var issue = {}
6567 var issueMsg
@@ -95,11 +97,13 @@
9597 old: true, live: false, sync: false}),
9698 pull.drain(onOldMsg, onOldEnd)
9799 )
98100 // keep the results up-to-date in the future
101 + var read = ssb.links({dest: id, values: true,
102 + old: false, live: true, sync: false})
103 + liveStreams.push(read)
99104 pull(
100- ssb.links({dest: id, values: true,
101- old: false, live: true, sync: false}),
105 + read,
102106 pull.drain(onNewMsg, onNewEnd)
103107 )
104108 }
105109
@@ -191,8 +195,17 @@
191195 }
192196 }
193197 })
194198
199 + function deinit(cb) {
200 + var done = multicb()
201 + // cancel all live streams
202 + liveStreams.forEach(function (read) {
203 + read(true, done())
204 + })
205 + done(cb)
206 + }
207 +
195208 function listIssues(opts) {
196209 opts.type = 'issue'
197210 return pull(
198211 // TODO: use links2 for this
@@ -239,8 +252,9 @@
239252 })
240253 }
241254
242255 return {
256 + deinit: deinit,
243257 get: getIssue,
244258 list: listIssues,
245259 new: newIssue,
246260 edit: editIssue,
package.jsonView
@@ -10,8 +10,9 @@
1010 "test": "node test"
1111 },
1212 "dependencies": {
1313 "asyncmemo": "^0.1.0",
14 + "multicb": "^1.2.1",
1415 "pull-paramap": "^1.1.2",
1516 "pull-stream": "^3.2.0",
1617 "ssb-msgs": "^5.2.0",
1718 "ssb-ref": "^2.3.0"

Built with git-ssb-web