fix posix.onSignal example, inject current signal as s
This commit is contained in:
parent
fedd695d76
commit
4c6382a334
1 changed files with 11 additions and 5 deletions
|
|
@ -985,12 +985,18 @@ 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>".}
|
||||
|
||||
template onSignal*(signals: varargs[cint], body: untyped) =
|
||||
## Setup code to be executed when Unix signals are received. Example:
|
||||
## from posix import SIGINT, SIGTERM
|
||||
## onSignal(SIGINT, SIGTERM):
|
||||
## echo "bye"
|
||||
## Setup code to be executed when Unix signals are received. The
|
||||
## currently handled signal is injected as ``s`` into the calling
|
||||
## scope.
|
||||
##
|
||||
## Example:
|
||||
##
|
||||
## .. code-block::
|
||||
## from posix import SIGINT, SIGTERM
|
||||
## onSignal(SIGINT, SIGTERM):
|
||||
## echo "bye from signal ", s
|
||||
|
||||
for s in signals:
|
||||
for s {.inject.} in signals:
|
||||
handle_signal(s,
|
||||
proc (sig: cint) {.noconv.} =
|
||||
body
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue