Change empty callback into nil
This commit is contained in:
parent
06c32aab29
commit
2f3add99bb
1 changed files with 12 additions and 9 deletions
|
|
@ -236,8 +236,8 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
|
||||||
proc execProcesses*(cmds: openArray[string],
|
proc execProcesses*(cmds: openArray[string],
|
||||||
options = {poStdErrToStdOut, poParentStreams},
|
options = {poStdErrToStdOut, poParentStreams},
|
||||||
n = countProcessors(),
|
n = countProcessors(),
|
||||||
beforeRunEvent: proc(idx: int){.closure.}): int
|
beforeRunEvent: proc(idx: int)): int
|
||||||
{.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
|
{.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} =
|
||||||
## executes the commands `cmds` in parallel. Creates `n` processes
|
## executes the commands `cmds` in parallel. Creates `n` processes
|
||||||
## that execute in parallel. The highest return value of all processes
|
## that execute in parallel. The highest return value of all processes
|
||||||
## is returned. Runs `beforeRunEvent` before running each command.
|
## is returned. Runs `beforeRunEvent` before running each command.
|
||||||
|
|
@ -251,6 +251,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
newSeq(q, n)
|
newSeq(q, n)
|
||||||
var m = min(n, cmds.len)
|
var m = min(n, cmds.len)
|
||||||
for i in 0..m-1:
|
for i in 0..m-1:
|
||||||
|
if beforeRunEvent != nil:
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
q[i] = startCmd(cmds[i], options=options)
|
q[i] = startCmd(cmds[i], options=options)
|
||||||
when defined(noBusyWaiting):
|
when defined(noBusyWaiting):
|
||||||
|
|
@ -265,6 +266,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
echo(err)
|
echo(err)
|
||||||
result = max(waitForExit(q[r]), result)
|
result = max(waitForExit(q[r]), result)
|
||||||
if q[r] != nil: close(q[r])
|
if q[r] != nil: close(q[r])
|
||||||
|
if beforeRunEvent != nil:
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
q[r] = startCmd(cmds[i], options=options)
|
q[r] = startCmd(cmds[i], options=options)
|
||||||
r = (r + 1) mod n
|
r = (r + 1) mod n
|
||||||
|
|
@ -277,6 +279,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
#echo(outputStream(q[r]).readLine())
|
#echo(outputStream(q[r]).readLine())
|
||||||
result = max(waitForExit(q[r]), result)
|
result = max(waitForExit(q[r]), result)
|
||||||
if q[r] != nil: close(q[r])
|
if q[r] != nil: close(q[r])
|
||||||
|
if beforeRunEvent != nil:
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
q[r] = startCmd(cmds[i], options=options)
|
q[r] = startCmd(cmds[i], options=options)
|
||||||
inc(i)
|
inc(i)
|
||||||
|
|
@ -286,21 +289,21 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
if q[j] != nil: close(q[j])
|
if q[j] != nil: close(q[j])
|
||||||
else:
|
else:
|
||||||
for i in 0..high(cmds):
|
for i in 0..high(cmds):
|
||||||
|
if beforeRunEvent != nil:
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
var p = startCmd(cmds[i], options=options)
|
var p = startCmd(cmds[i], options=options)
|
||||||
result = max(waitForExit(p), result)
|
result = max(waitForExit(p), result)
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
let emptyCb = proc(idx: int) {.closure.} = discard
|
|
||||||
proc execProcesses*(cmds: openArray[string],
|
proc execProcesses*(cmds: openArray[string],
|
||||||
options = {poStdErrToStdOut, poParentStreams},
|
options = {poStdErrToStdOut, poParentStreams},
|
||||||
n = countProcessors()): int
|
n = countProcessors()): int
|
||||||
{.rtl, extern: "nosp$1",
|
{.rtl, extern: "nosp$1",
|
||||||
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
|
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} =
|
||||||
## executes the commands `cmds` in parallel. Creates `n` processes
|
## executes the commands `cmds` in parallel. Creates `n` processes
|
||||||
## that execute in parallel. The highest return value of all processes
|
## that execute in parallel. The highest return value of all processes
|
||||||
## is returned.
|
## is returned.
|
||||||
return execProcesses(cmds, options, n, emptyCb)
|
return execProcesses(cmds, options, n, nil)
|
||||||
|
|
||||||
proc select*(readfds: var seq[Process], timeout = 500): int
|
proc select*(readfds: var seq[Process], timeout = 500): int
|
||||||
## `select` with a sensible Nim interface. `timeout` is in miliseconds.
|
## `select` with a sensible Nim interface. `timeout` is in miliseconds.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue