Wake up from sleep - Erlang

Is it possible to cause a process from outside in Erlang after it has been sent to infinity?

I would like to wake it from another process that holds the process id of the process that is sleeping.

I used this in a process that I want to sleep:

timer:sleep(infinity)

If you cannot wake him from the outside, what other options are available to me?

+4
source share
2 answers

Instead of using timer:sleep/1, translate the process in receiveso that it waits for a message. When another process wants it to continue, it can simply send a message to it. Assuming the message matches what it is looking for receive, the first process will exit receiveand continue.

+8

:

-spec sleep(Time) -> 'ok' when
  Time :: timeout().
sleep(T) ->
    receive
    after T -> ok
    end.

, sleep , .

, receive.

+1

Source: https://habr.com/ru/post/1532007/


All Articles