core/std: finish making futures sendable + test.. still issues

This commit is contained in:
Jeff Olson 2012-08-28 06:43:58 -07:00 committed by Brian Anderson
parent 6bdda1e0de
commit 27129c6aba
3 changed files with 17 additions and 8 deletions

View File

@ -37,7 +37,7 @@ struct Future<A> {
}
priv enum FutureState<A> {
Pending(fn@() -> A),
Pending(fn~() -> A),
Evaluating,
Forced(A)
}
@ -93,7 +93,7 @@ fn from_port<A:Send>(+port: future_pipe::client::waiting<A>) -> Future<A> {
}
}
fn from_fn<A>(+f: @fn() -> A) -> Future<A> {
fn from_fn<A>(+f: ~fn() -> A) -> Future<A> {
/*!
* Create a future from a function.
*
@ -239,4 +239,14 @@ mod test {
let f = spawn(|| fail);
let _x: ~str = get(&f);
}
}
#[test]
fn test_sendable_future() {
let expected = ~"schlorf";
let f = do spawn |copy expected| { expected };
do task::spawn {
let actual = get(&f);
assert actual == expected;
}
}
}

View File

@ -1754,7 +1754,7 @@ fn test_spawn_linked_sup_fail_down() { // parent fails; child fails
opts.supervised = true;
move opts
};
let b0 = task();
let b1 = TaskBuilder({
opts: move opts,

View File

@ -285,15 +285,14 @@ fn future_writer_factory(
}
fn future_writer() -> (writer, future::Future<~str>) {
let port = comm::Port();
let chan = comm::Chan(port);
let (chan, port) = pipes::stream();
let writer = fn~(+instr: writeinstr) {
comm::send(chan, copy instr);
chan.send(copy instr);
};
let future = do future::from_fn {
let mut res = ~"";
loop {
match comm::recv(port) {
match port.recv() {
write(s) => res += s,
done => break
}