Last active
December 15, 2015 20:19
-
-
Save jimeh/5317406 to your computer and use it in GitHub Desktop.
Ice Coffee Script vs Promises/A (as I've understood it at least)
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
search = (keyword, callback) -> | |
host = "http://search.twitter.com/" | |
url = "#{host}/search.json?q=#{keyword}&callback=?" | |
await $.getJSON(url, defer(json)) | |
callback json.results | |
search "hello world", (results) -> console.log(results) |
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
search = (keyword) -> | |
host = "http://search.twitter.com/" | |
url = "#{host}/search.json?q=#{keyword}&callback=?" | |
$.getJSON(url) # returns a promise | |
promise = search("hello world") | |
promise.then (results) -> console.log(results) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I prefer the straight ahead promise approach