summary refs log tree commit diff stats
path: root/lib/pure
diff options
context:
space:
mode:
authorErwan Ameil <wan@idlewan.com>2014-11-02 15:55:33 +0100
committerErwan Ameil <wan@idlewan.com>2014-11-02 15:55:33 +0100
commit2f3add99bb1928b7dbc483c711ae17028f913804 (patch)
treef37f4967f62bd9978bee302b0c7c40830f4e11ed /lib/pure
parent06c32aab29b0e33653aa9c144bfe4994e706a84e (diff)
downloadNim-2f3add99bb1928b7dbc483c711ae17028f913804.tar.gz
Change empty callback into nil
Diffstat (limited to 'lib/pure')
-rw-r--r--lib/pure/osproc.nim21
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index 35183c37c..d51a2b224 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -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.