You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To support this, we should return Promise from got.
Also new fetch API based on Promises landed in Chrome 42.
When ES7 will come to play, we will be able to go even further with async/await:
asyncfunction(){letsite=awaitgot('google.com');};
Problems
Promise API conflicts with Stream API
Atm I have no idea how to merge them (and if it is possible, I would vote against it), so one way is to move Stream API under stream property, like this:
varstream=got.stream('google.com');
This will be breaking change, so "brace yourselves, major release is coming" (hah). What we can do in 3.x version, to warn users - add promise property first and deprecation warning of Stream API.
Resolve format
There are two ways, with which Promise can resolve request. This will affect, how results can be destructed into variables:
Resolve into Array of response and body (like then-got):
// Assume co-wrapper in all examples below ↓var[response,body]=yieldgot('google.com');
Resolve into response Object with body property (like got-promise):
var{body, headers}=yieldgot('google.com');
It seems like resolving to Object make much more sens - order of vars is not matters and user can access body, without response (or vice versa with different order).
It seems like resolving to Object make much more sens - order of vars is not matters and user can access body, without response (or vice versa with different order).
It seems like resolving to Object make much more sens - order of vars is not matters and user can access body, without response (or vice versa with different order).
This is just a proposal - feel free to share ideas, criticize, etc.
Idea
Get Promise API into
got
with polyfill for Promise in Node.JS0.10
like this:Motivation
✨Generators✨ are awesome for flow-control and we finally can forget about callback hell and move on (with some help of
co
-like libraries) toyield
:To support this, we should return Promise from got.
Also new
fetch API
based on Promises landed in Chrome 42.When ES7 will come to play, we will be able to go even further with
async
/await
:Problems
Atm I have no idea how to merge them (and if it is possible, I would vote against it), so one way is to move Stream API under
stream
property, like this:This will be breaking change, so "brace yourselves, major release is coming" (hah). What we can do in
3.x
version, to warn users - addpromise
property first and deprecation warning of Stream API.Resolve format
There are two ways, with which Promise can resolve request. This will affect, how results can be destructed into variables:
Resolve into Array of
response
andbody
(like then-got):Resolve into response Object with
body
property (like got-promise):It seems like resolving to Object make much more sens - order of vars is not matters and user can access body, without response (or vice versa with different order).
TS: @sindresorhus
Related: request/request#796
The text was updated successfully, but these errors were encountered: