Files: fd48051c9a0ccc1e5fd254db048758d8eff91383 / once-true.js
315 bytesRaw
1 | var watch = require('./watch') |
2 | module.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