Skip to content

Commit

Permalink
core/std: finish making futures sendable + test.. still issues
Browse files Browse the repository at this point in the history
  • Loading branch information
olsonjeffery authored and brson committed Sep 8, 2012
1 parent 6bdda1e commit 27129c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
16 changes: 13 additions & 3 deletions src/libcore/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct Future<A> {
}

priv enum FutureState<A> {
Pending(fn@() -> A),
Pending(fn~() -> A),
Evaluating,
Forced(A)
}
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/libcore/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions src/rustdoc/markdown_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 27129c6

Please sign in to comment.