Created
February 7, 2015 07:52
-
-
Save mkyung/19740c313571356f1d69 to your computer and use it in GitHub Desktop.
An example of using Q.spawn with generator and yield a request
This file contains hidden or 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
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