Skip to content

Instantly share code, notes, and snippets.

@winton
Created November 12, 2012 06:49
Show Gist options
  • Select an option

  • Save winton/4057862 to your computer and use it in GitHub Desktop.

Select an option

Save winton/4057862 to your computer and use it in GitHub Desktop.
Starting point for playing with Promises/when.js
When = require('when')
x = ->
d = When.defer()
#d.resolve('hello')
d.reject('hello')
d.promise
console.log ""
x().then(
(a) ->
console.log("* 1 success(#{a})")
console.log(" raising error")
throw new Error("1 success exception")
(a) ->
console.log("* 1 error(#{a})")
console.log(" raising error")
throw new Error("1 error exception")
).then(
(a) ->
console.log("* 2 success(#{a})")
(a) ->
console.log("* 2 error(#{a})")
console.log(" raising error")
throw new Error("2 error exception")
).then(
(a) ->
console.log("* 3 success(#{a})")
).then(
(a) ->
console.log("* 4 success(#{a})")
(a) ->
console.log("* 4 error(#{a})")
)
console.log ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment