Skip to content
Advertisement

Does future in c++ corresponding to promise in javascript?

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:

  1. does std::future in c++ corresponding to promise in javascript?
  2. if 1 is true, why they confused future and promise?

Advertisement

Answer

  1. Yes.
  2. 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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement