git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 8397cee5bd7b17b9f2ebf584813ed0c0a035023d

Files: 8397cee5bd7b17b9f2ebf584813ed0c0a035023d / lib / once-true.js

320 bytesRaw
1var watch = require('mutant/watch')
2module.exports = function onceTrue (value, fn) {
3 var done = false
4 var release = watch(value, (v) => {
5 if (v && !done) {
6 done = true
7 setImmediate(doRelease)
8 fn(v)
9 }
10 }, { nextTick: true })
11
12 return release
13
14 function doRelease () {
15 release()
16 }
17}
18

Built with git-ssb-web