Are there promise standards for extended functions like .all(), .finally(), etc

前端 未结 1 592
刺人心
刺人心 2020-12-21 13:13

Are there standards or emerging standards for extended promise functions such as .all(), .finally(), .catch(), .spread(),

相关标签:
1条回答
  • 2020-12-21 13:42

    I know about the Promises A+ spec, but that only appears to deal with .then()

    Yes. The aim of the Promises/A+ spec is to "detail the behavior of the then method, providing an interoperable base which all Promises/A+ conformant promise implementations can be depended on to provide" and also describes promise assimilation, i.e. how to convert a promise-like object to a "real" Promise of your own library. In one word, it focuses on interoperability by speccing the minimum interface.

    I can't find standards for all the other useful functions.

    Yes. Every library does define its own. "Standards" emerge when a particular feature is present in (and copied to) many implementations.

    My motivation for wanting to understand what the current and future standards development looks like is to know which current functions offered in the various libraries are more likely to be consistent with future standards and which are not so I can write code that will need less maintenance in this area in the future.

    Probably watching the issue discussions of the big implementations is the best idea. However, most of the offered features are relatively easy to polyfill.

    The gold standard will be ES6 and ES7. Check the esdiscuss mailing list regularly for discussion of features, questions on the usage, and new drafts.

    I can see Promise.all() in an ES6 draft spec, but don't see any of the others.

    If you look more closely, the Promise section details:

    • The Promise constructor, Promise.reject and Promise.resolve
    • Promise.all and Promise.race
    • Promise.prototype.catch and Promise.prototype.then

    .finally(), .catch(), .spread(), .settle()

    • finally was discussed on esdiscuss (e.g. here), but probably won't make it into ES6.
    • see above for catch
    • spread is superseded by the spread operator and destructuring
    • settle could be implemented using all, or at least using an algorithm very close to the all spec
    0 讨论(0)
提交回复
热议问题