Answer the question
In order to leave comments, you need to log in
Function Synchronization in JSDeferred
Started looking at the library. Why might this code not work?
Deferred = (require './libs/jsdeferred.js').Deferred
Deferred.define()
func = (s, t)->
def = new Deferred()
console.log "Im works"
setTimeout(()->
console.log s
, t)
return def
next(()->
return func("Hello", 3000)
).next(()->
return func("World", 1000)
)
$ coffee test.coffee
Im works
Hello
Answer the question
In order to leave comments, you need to log in
You need to explicitly call deferred.call in the setTimeout callback
Try this
Deferred = (require './libs/jsdeferred.js').Deferred
Deferred.define()
func = (s, t)->
def = new Deferred()
console.log "Im works"
setTimeout(()->
console.log s
def.call
, t)
return def
next(()->
return func("Hello", 3000)
).next(()->
return func("World", 1000)
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question