Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core/std: finish making futures sendable + test.. still issues
  • Loading branch information
olsonjeffery committed Sep 8, 2012
commit 44c0788696badf231bcd33408d12e2e4ec375356
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