Change empty callback into nil

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

View file

@ -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,7 +251,8 @@ 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:
beforeRunEvent(i) if beforeRunEvent != nil:
beforeRunEvent(i)
q[i] = startCmd(cmds[i], options=options) q[i] = startCmd(cmds[i], options=options)
when defined(noBusyWaiting): when defined(noBusyWaiting):
var r = 0 var r = 0
@ -265,7 +266,8 @@ 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])
beforeRunEvent(i) if beforeRunEvent != nil:
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
else: else:
@ -277,7 +279,8 @@ 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])
beforeRunEvent(i) if beforeRunEvent != nil:
beforeRunEvent(i)
q[r] = startCmd(cmds[i], options=options) q[r] = startCmd(cmds[i], options=options)
inc(i) inc(i)
if i > high(cmds): break if i > high(cmds): break
@ -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):
beforeRunEvent(i) if beforeRunEvent != nil:
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.