Differences Between Deferreds, Promises, and Futures in JavaScript
In JavaScript, deferreds, promises, and futures are commonly used to handle asynchronous operations. Each of these concepts has its own unique set of characteristics:
Deferreds
Never clearly defined in formal documentation, deferreds are typically used as the arbiter of promise resolution, implementing both resolve and reject functions. They may also be implemented as promises, enabling the use of the then function.
Promises
Promises represent the most comprehensive concept in this context. They encapsulate the result of an asynchronous operation, exposing a then function that accepts another target function. The Promises/A specification sets standards for how promises should behave, resolving ambiguity from the earlier Promises/A specification.
Futures
A term less commonly used in current discussions, futures refer to a proxy object that abstracts synchronicity and error handling without providing then functionality. FutureJS, for example, employs the term generically for such purposes.
Key Differences
In summary, while these terms may sometimes be used interchangeably, they each hold distinct characteristics. Deferreds are the driving force behind promise resolution, promises represent the overall strategy for asynchronous operations, and futures are a less commonly used term for abstracting synchronicity.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3