Skip to content

Instantly share code, notes, and snippets.

@brson
Created July 28, 2011 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brson/1112723 to your computer and use it in GitHub Desktop.
Save brson/1112723 to your computer and use it in GitHub Desktop.
use std;
import std::task;
tag request {
quit;
close(int, chan[bool]);
}
type ctx = chan[request];
fn request_task(c: chan[ctx]) {
let p: port[request] = port();
c <| chan(p);
let req: request;
while (true) {
p |> req;
alt (req) {
close(what, status) {
log "closing now";
log what;
status <| true;
}
quit {
ret;
}
}
}
}
fn new() -> ctx {
let p: port[ctx] = port();
let t = spawn request_task(chan(p));
let cx: ctx;
p |> cx;
ret cx;
}
fn main() {
let cx = new();
let p: port[bool] = port();
cx <| close(4, chan(p));
let result: bool;
p |> result;
cx <| quit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment