git ssb

1+

Dominic / secure-scuttlebutt



Tree: 533b73eebb0583f344a236933331d527606ed657

Files: 533b73eebb0583f344a236933331d527606ed657 / util.js

873 bytesRaw
1
2 // opts standardized to work like levelup api
3 function stdopts (opts) {
4 opts = opts || {}
5 opts.keys = opts.keys !== false //default keys to true
6 opts.values = opts.values !== false //default values to true
7 return opts
8 }
9
10 function msgFmt (keys, values, obj) {
11 if (keys && values)
12 return obj
13 if (keys)
14 return obj.key
15 if (values)
16 return obj.value
17 return null // i guess?
18 }
19
20exports.options = stdopts
21exports.format = msgFmt
22
23exports.lo = null
24exports.hi = undefined
25
26exports.await = function () {
27 var waiting = [], value
28 return {
29 get: function () { return value },
30 set: function (_value) {
31 value = _value
32 while(waiting.length)
33 waiting.shift()(null, value)
34 },
35 await: function (cb) {
36 if(value !== undefined) cb(null, value)
37 else waiting.push(cb)
38 }
39 }
40}
41
42
43
44

Built with git-ssb-web