shithub: mc

Download patch

ref: aa40abd25de6fc94621a41b360b5808b3aa57b55
parent: 492aca3ff6f829ee09c52e17c86a808430ee7df4
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Jul 17 20:24:29 EDT 2017

Add the abiity to wait for any proc.

--- a/lib/std/wait+posixy.myr
+++ b/lib/std/wait+posixy.myr
@@ -12,13 +12,27 @@
 	;;
 
 	const wait	: (pid : pid -> waitstatus)
+	const waitany	: (-> (pid, waitstatus))
 ;;
 
+const waitany = {
+	match dowait(-1)
+	| (p, st):	-> ((p : pid), st)
+	;;
+}
+
 const wait = {pid
-	var st
+	match dowait(pid)
+	| (_, st):	-> st
+	;;
+}
 
+const dowait = {pid
+	var st, p
+
 :again
-	if sys.waitpid((pid : sys.pid), &st, 0) > 0
+	p = sys.waitpid((pid : sys.pid), &st, 0)
+	if p > 0
 		match sys.waitstatus(st)
 		/* 
 		when a process stops, eg, if paused by a debugger,
@@ -26,16 +40,12 @@
 		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
-			;;
+		| `sys.Waitfail fail:	-> (p, `Waiterror)
+		| `sys.Waitsig sig:	-> (p, `Wsignalled)
+		| `sys.Waitexit 0:	-> (p, `Wsuccess)
+		| `sys.Waitexit _:	-> (p, `Wfailure)
 		;;
 	;;
-	-> `Waiterror
+	-> (-1, `Waiterror)
 }