Signals are used to generate IO.Promises that resolve when a specific signal is received.
A Signal can be in one of 3 states:
- Right after construction it's initial.
- While it is listening for signals it's running.
- If it has stopped for some reason it's finished.
This together with whether it was set up as repeating with Signal.mk determines the behavior
of all functions on Signals.
Instances For
@[extern lean_uv_signal_mk]
This creates a Signal in the initial state and doesn't start listening yet.
- If
repeatingisfalsethis constructs a signal handler that resolves once when the specified signalsignumis received, then automatically stops listening. - If
repeatingistruethis constructs a signal handler that resolves each time the specified signalsignumis received and continues listening. A repeating signal handler will only be freed afterSignal.stopis called.
@[extern lean_uv_signal_next]
This function has different behavior depending on the state and configuration of the Signal:
- if
repeatingisfalseand:- it is initial, start listening and return a new
IO.Promisethat is set to resolve once the signalsignumis received. After thisIO.Promiseis resolved theSignalis finished. - it is running or finished, return the same
IO.Promisethat the first call tonextreturned.
- it is initial, start listening and return a new
- if
repeatingistrueand:- it is initial, start listening and return a new
IO.Promisethat resolves when the next signalsignumis received. - it is running, check whether the last returned
IO.Promiseis already resolved:- If it is, return a new
IO.Promisethat resolves upon receiving the next signal - If it is not, return the last
IO.PromiseThis ensures that the returnedIO.Promiseresolves at the next occurrence of the signal.
- If it is, return a new
- if it is finished, return the last
IO.Promisecreated bynext. Notably this could be one that never resolves if the signal handler was stopped before fulfilling the last one.
- it is initial, start listening and return a new
The resolved IO.Promise contains the signal number that was received.
@[extern lean_uv_signal_stop]
This function has different behavior depending on the state of the Signal:
- If it is initial or finished this is a no-op.
- If it is running the signal handler is stopped and it is put into the finished state.
Note that if the last
IO.Promisegenerated bynextis unresolved and being waited on this creates a memory leak and the waiting task is not going to be awoken anymore.
@[extern lean_uv_signal_cancel]
This function has different behavior depending on the state of the Signal:
- If it is initial or finished this is a no-op.
- If it's running then it drops the accept promise and if it's not repeatable it sets the signal handler to the initial state.