philipbohun.com

Glojure by Example: Signals

os/signal.Notify relays selected signals to a Go channel. os.Signal is the channel's element type, and os.Interrupt is Ctrl-C. Receive with go/recv and the program keeps running after the signal.

(def ch (go/make (go/chan-of os.Signal) 1))
(os:signal.Notify ch os.Interrupt)
(println "waiting")
(let [[sig ok] (go/recv ch)]
  (println "got" (str sig) ok))

Run the program, then send it an interrupt.

$ glj signals.glj
waiting
got interrupt true

Next example: Exit.