11= Signal Handling in Swift
22François Lamboley <
francois [email protected] >
33
4- This package gives you a Swift syntax for the low-level C `sigaction` function,
5- and provides a way to delay signals until the registered handlers allow the
6- signal to go through.
4+ This package provides a Swift syntax for the low-level C `sigaction` function
5+ and a way to delay or cancel sigaction handlers.
76
87== Example of Use
98
@@ -19,25 +18,27 @@ let action = Sigaction(handler: .ansiC({ sigID in
1918try action.install(on: .terminated)
2019----
2120
22- Example of a delayed signal :
21+ Example of a delayed sigaction :
2322
2423[source,swift]
2524----
2625let delayedSigaction = try SigactionDelayer_Unsig.registerDelayedSigaction(Signal.terminated, handler: { signal, doneHandler in
2726 logger.debug("Received signal \(signal); delaying it to clean-up")
28- asyncCleanUp {
27+ myAsyncCleanUp {
2928 logger.debug("Cleanup is done, allowing signal to go through")
3029 doneHandler(true)
3130 })
3231})
3332----
3433
35- When both examples are put in the same code, when the program receives the
36- terminated signal (15 on macOS), the following should be logged:
34+ With both examples in the same code, when the program receives the terminated
35+ signal (15 on macOS), the following will be logged:
3736
3837[source,text]
3938----
4039Received signal SIGTERM; delaying it to clean-up
4140Cleanup is done, allowing signal to go through
4241Handling signal SIGTERM from sigaction
4342----
43+
44+ == How Does Delaying the Sigaction Work?
0 commit comments