Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created April 3, 2013 04:30
Show Gist options
  • Save hitode909/5298455 to your computer and use it in GitHub Desktop.
Save hitode909/5298455 to your computer and use it in GitHub Desktop.
流れるようなインターフェイス
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