Created
July 28, 2011 22:30
-
-
Save brson/1112731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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