2011-07-28 20:01:27 -05:00
|
|
|
// Issue #763
|
|
|
|
|
|
|
|
use std;
|
2011-12-13 18:25:51 -06:00
|
|
|
import task;
|
|
|
|
import comm::chan;
|
|
|
|
import comm::send;
|
|
|
|
import comm;
|
|
|
|
import comm::port;
|
|
|
|
import comm::recv;
|
2011-07-28 20:01:27 -05:00
|
|
|
|
2012-01-19 20:31:08 -06:00
|
|
|
enum request { quit, close(chan<bool>), }
|
2011-07-28 20:01:27 -05:00
|
|
|
|
2011-08-25 13:20:43 -05:00
|
|
|
type ctx = chan<request>;
|
2011-07-28 20:01:27 -05:00
|
|
|
|
2011-10-20 22:34:04 -05:00
|
|
|
fn request_task(c: chan<ctx>) {
|
2011-08-25 13:20:43 -05:00
|
|
|
let p = port();
|
|
|
|
send(c, chan(p));
|
2011-07-28 20:01:27 -05:00
|
|
|
let req: request;
|
2011-08-25 13:20:43 -05:00
|
|
|
req = recv(p);
|
2011-07-28 20:01:27 -05:00
|
|
|
// Need to drop req before receiving it again
|
2011-08-25 13:20:43 -05:00
|
|
|
req = recv(p);
|
2011-07-28 20:01:27 -05:00
|
|
|
}
|
|
|
|
|
2012-03-14 14:16:46 -05:00
|
|
|
fn new_cx() -> ctx {
|
2011-08-25 13:20:43 -05:00
|
|
|
let p = port();
|
2012-01-04 23:14:53 -06:00
|
|
|
let ch = chan(p);
|
|
|
|
let t = task::spawn {|| request_task(ch); };
|
2011-07-28 20:01:27 -05:00
|
|
|
let cx: ctx;
|
2011-08-25 13:20:43 -05:00
|
|
|
cx = recv(p);
|
2011-07-28 20:01:27 -05:00
|
|
|
ret cx;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2012-03-14 14:16:46 -05:00
|
|
|
let cx = new_cx();
|
2011-07-28 20:01:27 -05:00
|
|
|
|
2011-08-25 13:20:43 -05:00
|
|
|
let p = port::<bool>();
|
|
|
|
send(cx, close(chan(p)));
|
2011-08-13 17:20:11 -05:00
|
|
|
send(cx, quit);
|
2011-07-28 20:01:27 -05:00
|
|
|
}
|