git ssb

10+

Matt McKegg / patchwork



Tree: 01436b0a000173e48f00729b2c1f7b5b3cc4243d

Files: 01436b0a000173e48f00729b2c1f7b5b3cc4243d / lib / once-true.js

329 bytesRaw
1var watch = require('@mmckegg/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