Skip to content

Instantly share code, notes, and snippets.

@michaelavila
Last active December 24, 2015 06:59
Show Gist options
  • Save michaelavila/6760642 to your computer and use it in GitHub Desktop.
Save michaelavila/6760642 to your computer and use it in GitHub Desktop.
Orc vs Promises 2
url = 'http://fiddle.jshell.net'
step1 = ->
$.ajax url,
complete: orc.waitFor()
error: (error) ->
console.log 'Step 1 failed: Ajax request'
step2 = ->
setTimeout orc.waitFor(->
console.log 'Request completed'
), 2000
orc.sequence step1, step2, ->
console.log 'Sequence completed'
setTimeout (-> console.log 'end'), 1000
url = 'http://fiddle.jshell.net'
step1 = $.ajax url
step2 = step1.then(
((data) ->
def = new $.Deferred
setTimeout (->
console.log 'Request completed'
def.resolve()
), 2000
return def.promise()
),
((err) ->
console.log 'Step1 failed: Ajax request'
)
)
step2.done ->
console.log 'Sequence completed'
setTimeout (->
console.log 'end'
), 1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment