bottleneck
Version:
Distributed task scheduler and rate limiter
29 lines (18 loc) • 738 B
text/coffeescript
DLList = require "./DLList"
Events = require "./Events"
class Queues
constructor: (num_priorities) ->
= new Events @
= 0
= for i in [1..num_priorities] then new DLList @
incr: -> if ++ == 0 then .trigger "leftzero"
decr: -> if -- == 0 then .trigger "zero"
push: (priority, job) -> [priority].push job
queued: (priority) -> if priority? then [priority].length else
shiftAll: (fn) -> .forEach (list) -> list.forEachShift fn
getFirst: (arr=) ->
for list in arr
return list if list.length > 0
[]
shiftLastFrom: (priority) -> .shift()
module.exports = Queues