Created
July 28, 2011 04:35
-
-
Save robarnold/1110969 to your computer and use it in GitHub Desktop.
Minimal-ish test case
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(chan[ctx] c) { | |
let port[request] p = port(); | |
c <| chan(p); | |
let request req; | |
while (true) { | |
p |> req; | |
alt (req) { | |
case (quit) { | |
ret; | |
} | |
case (close(?what, ?status)) { | |
log "closing now"; | |
log what; | |
status <| true; | |
} | |
} | |
} | |
} | |
fn new() -> ctx { | |
let port[ctx] p = port(); | |
let task t = spawn request_task(chan(p)); | |
let ctx cx; | |
p |> cx; | |
ret cx; | |
} | |
fn main() { | |
let ctx cx = new(); | |
let port[bool] p = port(); | |
cx <| close(4, chan(p)); | |
let bool result; | |
p |> result; | |
cx <| quit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment