now es6 officially standard in node 4.x, how use promises? modules (for example native fs
module) automatically work promises? or modules have written work promises? how know can use promise , can't?
there have been many different promise implementations (q, bluebird, etc) confused on start native promises in node 4.x.
how use promises?
you can use "native" promises using new constructor, promise. basics of api can found over on mdn, , in-depth study of promises can found on html5rocks.
do modules (for example native fs module) automatically work promises?
they not, it's not difficult make wrapper. of course, doing whole node api bit tedious.
one of comments in op mentioned bluebird's promisifyall, seems magic way convert entire module use promises. nifty!
i expect promise-ified apis in coming versions of node, i'm not of this. there might issue or discussion somewhere around this...perhaps on io.js project. i'll investigate , update if find anything.
as why have promises and callback-style api? that's because of fact it's easier additive, adding promises, make possibly breaking api changes, removing callbacks.
or modules have written work promises?
they do.
how know can use promise , can't?
the documentation best place go api questions. don't know of returns promises, admittedly use small subset of node api in day-to-day.
there have been many different promise implementations (q, bluebird, etc) confused on start native promises in node 4.x.
do have specific questions these different implementations? way think native promises pretty minimal. they're enough make asynchronous code little bit cleaner, have no frills. other libraries mention 2 things:
- provide polyfill environments don't support native promises
- add varying degrees of fancy features
the first use case no longer necessary in node. it's matter of determining if want/need of fancy features.
let me know if answer isn't satisfactory, , i'll try update more info!
Comments
Post a Comment