Created
April 3, 2013 04:30
-
-
Save hitode909/5298455 to your computer and use it in GitHub Desktop.
流れるようなインターフェイス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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