0 | module System.UV.Signal
 1 |
 2 | import System.UV.Loop
 3 | import System.UV.Pointer
 4 | import System.UV.Raw.Handle
 5 | import public System.UV.Raw.Signal
 6 |
 7 | %default total
 8 |
 9 | parameters {auto cc : CloseCB}
10 |   export
11 |   Resource (Ptr Signal) where
12 |     release h = uv_close h cc
13 |
14 | parameters {auto l   : UVLoop}
15 |            {auto has : Has UVError es}
16 |   export
17 |   mkSignal : Async es (Ptr Signal)
18 |   mkSignal = mallocPtr Signal >>= uvAct (uv_signal_init l.loop)
19 |
20 |   ||| Reacts on process signals.
21 |   |||
22 |   ||| Note: If used in a do-block this will semantically block the
23 |   |||       current fiber.
24 |   |||       Wrap this in `start` to run it in the background.
25 |   export
26 |   onSignal : SigCode -> Async es SigCode
27 |   onSignal c =
28 |     uvCancelableAsync
29 |       mkSignal
30 |       (\p => liftIO $ ignore (uv_signal_stop p))
31 |       release
32 |       (\ps,cb => uv_signal_start ps (\_,_ => cb c) (sigToCode c))
33 |