heph
heph copied to clipboard
Actor monitoring
Erlang has a concept of process monitoring, which allows a process (actor) to know if another process stopped. Some resources about them:
- Erlang manual: https://erlang.org/doc/reference_manual/processes.html#monitors,
- API: https://erlang.org/doc/man/erlang.html#monitor-2,
- External books/tutorials: https://learnyousomeerlang.com/errors-and-processes and https://erlangbyexample.org/monitors.
I tried to replicated this concept in ActorRef::join
(#468), which returns Future<Output = ()>
which completes once an actor is stopped. But this doesn't give enough information. For testing for example you would also like to know if the actor stopped normally or returned an error (and wasn't restarted).
So I think we should expand the API: ActorRef::monitor(&self) -> Monitor
, where Monitor
is a Future<Output = ExitStatus>
,
enum ExitStatus {
Ok,
StoppedEarly, // Or Error.
}
Some alternative names: JoinResult
, RunResult
, ExitResult
, I'm not a huge fan of the Result
suffix as that reminds me of the Result
type, but many we can use that.
This also relates to the other APIs such as ActorGroup::join_all
(#472) and test::join
, test::join_many
and test::join_all
(#470).
A possible implementation would be for heph-inbox::Manager
to implement fn set_exit_status(self, ExiStatus)
. Then a new Sender::monitor
API similar to that of Sender::join
, but it returns this ExitStatus
.
Could maybe use something like https://github.com/Thomasdezeeuw/inbox/pull/32 for this.