Merge pull request #9059 from Vindaar/onSignalMod
fix `posix.onSignal` example, inject current signal as `s`
This commit is contained in:
commit
b0deb55814
1 changed files with 12 additions and 5 deletions
|
|
@ -985,14 +985,21 @@ proc utimes*(path: cstring, times: ptr array[2, Timeval]): int {.
|
||||||
proc handle_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.importc: "signal", header: "<signal.h>".}
|
proc handle_signal(sig: cint, handler: proc (a: cint) {.noconv.}) {.importc: "signal", header: "<signal.h>".}
|
||||||
|
|
||||||
template onSignal*(signals: varargs[cint], body: untyped) =
|
template onSignal*(signals: varargs[cint], body: untyped) =
|
||||||
## Setup code to be executed when Unix signals are received. Example:
|
## Setup code to be executed when Unix signals are received. The
|
||||||
## from posix import SIGINT, SIGTERM
|
## currently handled signal is injected as ``sig`` into the calling
|
||||||
## onSignal(SIGINT, SIGTERM):
|
## scope.
|
||||||
## echo "bye"
|
##
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
## .. code-block::
|
||||||
|
## from posix import SIGINT, SIGTERM
|
||||||
|
## onSignal(SIGINT, SIGTERM):
|
||||||
|
## echo "bye from signal ", sig
|
||||||
|
|
||||||
for s in signals:
|
for s in signals:
|
||||||
handle_signal(s,
|
handle_signal(s,
|
||||||
proc (sig: cint) {.noconv.} =
|
proc (signal: cint) {.noconv.} =
|
||||||
|
let sig {.inject.} = signal
|
||||||
body
|
body
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue