The benefits and drawbacks of promises and futures
There are advantages as well as some disadvantages of using promises and futures. Here are the main points.
Benefits
As high-level abstractions for managing asynchronous operations, writing and reasoning about concurrent code by using promises and futures is simplified and less error-prone.
Futures and promises enable concurrent execution of tasks, allowing the program to use multiple CPU cores efficiently. This can lead to improved performance and reduced execution time for computationally intensive tasks.
Also, they facilitate asynchronous programming by decoupling the initiation of an operation from its completion. As we will see later, this is particularly useful for I/O-bound tasks, such as network requests or file operations, where the program can continue executing other tasks while waiting for the asynchronous operation to complete. As a result, they can return a value but also an exception, allowing exception propagation...