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 | |
20 | exports.options = stdopts |
21 | exports.format = msgFmt |
22 | |
23 | exports.lo = null |
24 | exports.hi = undefined |
25 | |
26 | exports.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