summaryrefslogtreecommitdiff
path: root/lib/std/wait+posixy.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/wait+posixy.myr')
-rw-r--r--lib/std/wait+posixy.myr41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/std/wait+posixy.myr b/lib/std/wait+posixy.myr
new file mode 100644
index 0000000..a690feb
--- /dev/null
+++ b/lib/std/wait+posixy.myr
@@ -0,0 +1,41 @@
+use sys
+
+use "die.use"
+use "syswrap.use"
+
+pkg std =
+ type waitstatus = union
+ `Wsuccess
+ `Wfailure
+ `Wsignalled
+ `Waiterror
+ ;;
+
+ const wait : (pid : pid -> waitstatus)
+;;
+
+const wait = {pid
+ var st
+
+:again
+ if sys.waitpid(pid castto(sys.pid), &st, 0) > 0
+ match sys.waitstatus(st)
+ /*
+ when a process stops, eg, if paused by a debugger,
+ wait() will return. This API is for waiting until
+ a process exits. Loop instead.
+ */
+ | `sys.Waitstop sig: goto again
+ | `sys.Waitfail fail: -> `Waiterror
+ | `sys.Waitsig sig: -> `Wsignalled
+ | `sys.Waitexit status:
+ if status == 0
+ -> `Wsuccess
+ else
+ -> `Wfailure
+ ;;
+ ;;
+ ;;
+ -> `Waiterror
+}
+