Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yield does not return a response object #935

Closed
tremendus opened this issue Mar 10, 2016 · 2 comments
Closed

Yield does not return a response object #935

tremendus opened this issue Mar 10, 2016 · 2 comments

Comments

@tremendus
Copy link

Per the docs: http://visionmedia.github.io/superagent/ - at the end, there is this example under the section Generator Support:

var res = yield request
  .get('http://local')
  .auth('tobi', 'learnboost')

However, console.log(res) shows that it is a Request object, not a Response object. So without stuffing callbacks and wrapping in promises, what's the right way to get the response data out?

Is this a bug? Perhaps it is a partial code example and some other code is required?

@kornelski
Copy link
Contributor

In the current version .then is a bit of a hack #722, and depends on the generator being used by a Promise-wrapping library that will call .then() on it exactly only once. We're planning to fix it #925.

Does the following work for you?

var res = yield Promise.resolve(request
  .get('http://local')
  .auth('tobi', 'learnboost'))

@tremendus
Copy link
Author

Yeah, for my application this does work. Right now I'm wrapping it as a promise, but your passing it to resolve directly is more concise ... though there is no error handling here of course. But I can work with it anyway, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants