Does Erlang has equivalents for Future and Promises? Or since future and promises are solving a problem that doesn't exist in Erlang systems (synchronisation orchestrating for example), and hence we don't need them in Erlang.
If I want the semantics of futures and promises in Erlang, they could be emulated via Erlang processes/actors?
The RPC module contains the
rpc:async_call/4
function that does what you need. It will run a computation anywhere in a cluster (including onnode()
, the local node), and allow to have the result waited on withrpc:yield/1
:You can also poll in non-blocking ways by using
rpc:nb_yield/1
, or for a limited number of milliseconds withrpc:nb_yield/2
:That's all in the standard library and ready to be used.
You could easily implement a future in Erlang like this:
Having this functionality in a module and building chains from it should be easy too, but to be honest I never actually missed something like this. You are more flexible if you just freely send messages around.