Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Demo of DispatchSourceSignal for handling interrupts
import Darwin.C
import Dispatch
signal(SIGINT, SIG_IGN)
let source = DispatchSource.makeSignalSource(signal: SIGINT, queue: .main)
var count = 0
source.setEventHandler {
count += 1
print("Interrupted \(count) times.")
if count == 3 {
exit(0)
}
}
source.resume()
dispatchMain()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.