shithub: mc

ref: 34f2230c4a505f3b94bc33ed07f0839fe66a0e93
dir: /lib/thread/test/do.myr/

View raw version
use std
use thread

const main = {
	match std.espork(["/bin/echo", "hello"][:])
	| `std.Err e:
		std.fatal("could not spork\n")
	| `std.Ok (pid, in, out, err):
		std.close(in)
		var o = thread.do({;-> std.fslurp(out)})
		var e = thread.do({;-> std.fslurp(err)})
		var w = std.wait(pid)

		match w
		| `std.Wsuccess:	/* ok */
		| bad:	std.fatal("bad wait: {}\n", bad)
		;;

		match thread.futget(o)
		| `std.Ok "hello\n":	/* ok */
		| bad:	std.fatal("bad out: {}\n", bad)
		;;

		match thread.futget(e)
		| `std.Ok "":	/* ok */
		| bad:	std.fatal("bad err: {}\n", bad)
		;;
	;;
}