Skip to content

Instantly share code, notes, and snippets.

@cjbottaro
Last active August 29, 2015 13:57
Show Gist options
  • Save cjbottaro/9400140 to your computer and use it in GitHub Desktop.
Save cjbottaro/9400140 to your computer and use it in GitHub Desktop.
Promises and event handlers ?
doShow = ->
new RSVP.Promise (resolve, reject) ->
$("blah").off("shown.bs.modal")
$("blah").on "shown.bs.modal", (e) ->
resolve("I'm shown!")
$("blah").modal("show")
doShow().then (message) ->
console.log(message) # => "I'm shown!"
###
# Impl 2
###
resolvers = []
$("blah").on "shown.bs.modal", (e) ->
resolver = resolvers.shift()
if resolver?
resolver("I'm shown!")
doShow ->
promise = new RSVP.Promise (resolve, reject) ->
resolvers.push(resolve)
$("blah").modal("show")
promise
doShow().then (message) ->
console.log(message) # => "I'm shown!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment