Change empty callback into nil

This commit is contained in:
Erwan Ameil
2014-11-02 15:55:33 +01:00
parent 06c32aab29
commit 2f3add99bb

View File

@@ -236,8 +236,8 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
proc execProcesses*(cmds: openArray[string],
options = {poStdErrToStdOut, poParentStreams},
n = countProcessors(),
beforeRunEvent: proc(idx: int){.closure.}): int
{.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
beforeRunEvent: proc(idx: int)): int
{.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} =
## executes the commands `cmds` in parallel. Creates `n` processes
## that execute in parallel. The highest return value of all processes
## is returned. Runs `beforeRunEvent` before running each command.
@@ -251,7 +251,8 @@ proc execProcesses*(cmds: openArray[string],
newSeq(q, n)
var m = min(n, cmds.len)
for i in 0..m-1:
beforeRunEvent(i)
if beforeRunEvent != nil:
beforeRunEvent(i)
q[i] = startCmd(cmds[i], options=options)
when defined(noBusyWaiting):
var r = 0
@@ -265,7 +266,8 @@ proc execProcesses*(cmds: openArray[string],
echo(err)
result = max(waitForExit(q[r]), result)
if q[r] != nil: close(q[r])
beforeRunEvent(i)
if beforeRunEvent != nil:
beforeRunEvent(i)
q[r] = startCmd(cmds[i], options=options)
r = (r + 1) mod n
else:
@@ -277,7 +279,8 @@ proc execProcesses*(cmds: openArray[string],
#echo(outputStream(q[r]).readLine())
result = max(waitForExit(q[r]), result)
if q[r] != nil: close(q[r])
beforeRunEvent(i)
if beforeRunEvent != nil:
beforeRunEvent(i)
q[r] = startCmd(cmds[i], options=options)
inc(i)
if i > high(cmds): break
@@ -286,21 +289,21 @@ proc execProcesses*(cmds: openArray[string],
if q[j] != nil: close(q[j])
else:
for i in 0..high(cmds):
beforeRunEvent(i)
if beforeRunEvent != nil:
beforeRunEvent(i)
var p = startCmd(cmds[i], options=options)
result = max(waitForExit(p), result)
close(p)
let emptyCb = proc(idx: int) {.closure.} = discard
proc execProcesses*(cmds: openArray[string],
options = {poStdErrToStdOut, poParentStreams},
n = countProcessors()): int
{.rtl, extern: "nosp$1",
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} =
## executes the commands `cmds` in parallel. Creates `n` processes
## that execute in parallel. The highest return value of all processes
## is returned.
return execProcesses(cmds, options, n, emptyCb)
return execProcesses(cmds, options, n, nil)
proc select*(readfds: var seq[Process], timeout = 500): int
## `select` with a sensible Nim interface. `timeout` is in miliseconds.