git ssb

0+

Dominic / ssb-feed



Tree: 741d8d7903a47fb1572e9b2f2b0196a051559834

Files: 741d8d7903a47fb1572e9b2f2b0196a051559834 / queue.js

522 bytesRaw
1
2
3module.exports = function (async) {
4
5 var queue = [], working = false, prev = null
6
7 function start () {
8 if(working) return
9 working = true
10 ;(function next (item) {
11 async(item.value, prev, function (err, result) {
12 prev = result
13 if(item.cb) item.cb(err, result)
14 if(queue.length) next(queue.shift(), result)
15 else
16 working = false
17 })
18 })(queue.shift())
19 }
20
21 return function (value, cb) {
22 queue.push({value: value, cb: cb})
23 start()
24 }
25
26}
27
28
29
30
31
32
33

Built with git-ssb-web