Skip to content
heff

std.signal

For signals: the ones a program is sent — Ctrl-C, a kill, its terminal closed or resized — waited for, each a thing that happens outside it, as a read of a socket is. The C backend’s alone, and not on Windows. Import it by a name, import std.signal as Signal.

import cml as CML
import co
import std.io
import std.signal as Signal
-- | what comes on `jobs` done, until SIGTERM or Ctrl-C: then said so,
-- | and stopped
worked : {e w : HFunctor}
-> {{cm : CML.cml w <: e}}
-> {{sg : Signal.signals <: e}}
-> {{io : stdio <: e}}
-> CML.Chan w String
-> Co e Unit
worked jobs = do
next <-
(CML.choose
[ bind (CML.recv jobs) (\job -> pure (Right job))
, bind (Signal.wait [Terminate, Interrupt]) (\s -> pure (Left s))
]
: Co e (Either Signal.Signal String))
case next of
Right job -> do
print ("done: " ^ job)
worked jobs
Left s -> print ("stopping on " ^ show s)

A signal waited for is the program’s from then on: it no longer ends the program (nor is it ignored, where it was, as nohup has SIGHUP), and one that comes while no wait for it is pending is kept, given to the next — so a loop that waits again each round misses none. A signal never waited for is as it was: Ctrl-C, SIGTERM and SIGHUP end the program, and the commands std.process started with it. A program that stops on one it waited for ends as it ends otherwise, its commands ended at its end.

A wait is an outside operation of std.reactor’s: in a thread of cml’s scheduledWithReactor it is pending while the other threads go on — and in a choose, a base event, let go of where another branch is committed, the signal it was given, if any, kept for the next wait. Elsewhere the program waits where it is.

Signal

data Signal
= Interrupt
| Terminate
| Hangup
| Quit
| User1
| User2
| WindowChanged

A signal: Ctrl-C (SIGINT); asked to end (SIGTERM), as kill and a service manager ask; its terminal closed (SIGHUP); Ctrl-\ (SIGQUIT); the two left to programs (SIGUSR1, SIGUSR2); its terminal resized (SIGWINCH).

instanceShowSignal

instance instanceShowSignal : Show Signal

Its name, as the system’s tools say it.

>>> show (Terminate : Signal)
"SIGTERM"

SignalF

data SignalF (m : Type -> Type) x

signals

signals : HFunctor

For signals: waits for the first of some to come.

wait

wait : {e : HFunctor} -> {{sg : signals <: e}} -> List Signal -> Co e Signal

The first of the signals to come — one kept since it came, where there is, else the next — each the program’s from now on (of none, it waits for ever).