From 27129c6aba153299100887de5c8643cbe3e9b8ef Mon Sep 17 00:00:00 2001 From: Jeff Olson Date: Tue, 28 Aug 2012 06:43:58 -0700 Subject: [PATCH] core/std: finish making futures sendable + test.. still issues --- src/libcore/future.rs | 16 +++++++++++++--- src/libcore/task.rs | 2 +- src/rustdoc/markdown_writer.rs | 7 +++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 141fafcf7d7a..82deaf895376 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -37,7 +37,7 @@ struct Future { } priv enum FutureState { - Pending(fn@() -> A), + Pending(fn~() -> A), Evaluating, Forced(A) } @@ -93,7 +93,7 @@ fn from_port(+port: future_pipe::client::waiting) -> Future { } } -fn from_fn(+f: @fn() -> A) -> Future { +fn from_fn(+f: ~fn() -> A) -> Future { /*! * Create a future from a function. * @@ -239,4 +239,14 @@ mod test { let f = spawn(|| fail); let _x: ~str = get(&f); } -} \ No newline at end of file + + #[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; + } + } +} diff --git a/src/libcore/task.rs b/src/libcore/task.rs index cecc7a51ea78..3b1f9d8f845b 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -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, diff --git a/src/rustdoc/markdown_writer.rs b/src/rustdoc/markdown_writer.rs index c9d7fe0adb79..00c80366084a 100644 --- a/src/rustdoc/markdown_writer.rs +++ b/src/rustdoc/markdown_writer.rs @@ -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 }