Reputation: 350
I am a c++ programmer and tried to study std::future
and std::promise
these days. When I randomly search some information about future/promise, I found some discussion about future/promise in javascript and promise in javascript has then
function. In c++, even though std::future
don't have then
function now, but some proposal have mentioned it. So, there are two question:
std::future
in c++ corresponding to promise in javascript?Upvotes: 5
Views: 641
Reputation: 49058
Dynamically-typed languages sometimes combine concepts that are separated in statically-typed languages. A JavaScript promise is basically both a C++ promise and future. The resolve
and reject
functions in JavaScript roughly correspond to the promise side in C++, and the then
function in JavaScript roughly corresponds to the future side in C++.
then
also can compose promises in JavaScript, which you might consider a third feature, but in practice futures aren't very useful without composition.
Upvotes: 1
Reputation: 19123
std::future<T>
stands for a future result of T
, i.e. the object will at some point in the future hold a T
. std::promise<T>
is an object promising to provide a T
at some point in the future.Which language got the naming right is debatable.
Upvotes: 4