Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
流れるようなインターフェイス
class Worker
constructor: ->
@jobs = []
register: (job) ->
@jobs.push job
work: ->
job = do @jobs.shift
return unless job
job => do @work
worker = new Worker
worker.register (done) ->
console.log "1 do"
setTimeout ->
console.log "1 done"
do done
, 1000
worker.register (done) ->
console.log "2 do"
setTimeout ->
console.log "2 done"
do done
, 1000
worker.register (done) ->
console.log "3 do"
setTimeout ->
console.log "3 done"
do done
, 1000
do worker.work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.