git ssb

0+

Dominic / ssb-feed



Tree: eac1a89db33ba24513a85795a552c0f28da8c4bf

Files: eac1a89db33ba24513a85795a552c0f28da8c4bf / 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