Skip to content

Instantly share code, notes, and snippets.

@mkyung
Created February 7, 2015 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkyung/19740c313571356f1d69 to your computer and use it in GitHub Desktop.
Save mkyung/19740c313571356f1d69 to your computer and use it in GitHub Desktop.
An example of using Q.spawn with generator and yield a request
Q = require("q")
request = require("request")
# add a new GET method on top of the original GET
request.qget = (uri, options) ->
dfd = Q.defer()
request.get uri, options, (err, response, body) ->
if err
dfd.reject(err)
else
dfd.resolve([err, response, body])
dfd.promise
Q.spawn ->
[err, response, body] = yield request.qget("http://google.com")
console.log body
console.log "done!"
console.log "You should see me first"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment