xapi-connector
Version:
Simple low level connector for xAPI written in Coffeescript
39 lines (32 loc) • 917 B
text/coffeescript
###
The Dispatcher class.
It takes asynchronous requests to send something through the stream
and sends it asynchronously in intervals.
###
class Dispatcher
constructor: (, = 0, = 0) ->
= []
= 0
= false
= 0
add: (msg) ->
.push(msg)
if == false
return
getQue: () ->
return
_clearQue: () ->
= true
diff = new Date().getTime() -
if diff > or <
.write(msg = .shift())
= new Date().getTime()
if diff >
-= 1 if > 0 #substract a sin but not below 0
else
+= 1
if .length > 0 then else = false
else
setTimeout(.bind(@), + 1 - diff)
return
module.exports = Dispatcher