Skip to content

Move futures to std, etc #3842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 25, 2012
Merged
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
Next Next commit
core: Give future_pipe the same definition as pipes::oneshot
  • Loading branch information
brson committed Oct 23, 2012
commit 50f9925fabbc738f7be0df8148c99fae3e975bb1
20 changes: 13 additions & 7 deletions src/libcore/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn from_value<A>(val: A) -> Future<A> {
Future {state: Forced(~(move val))}
}

pub fn from_port<A:Send>(port: future_pipe::client::waiting<A>) ->
pub fn from_port<A:Send>(port: future_pipe::server::waiting<A>) ->
Future<A> {
/*!
* Create a future from a port
Expand Down Expand Up @@ -107,9 +107,15 @@ pub fn spawn<A:Send>(blk: fn~() -> A) -> Future<A> {
* value of the future.
*/

from_port(pipes::spawn_service_recv(future_pipe::init, |move blk, ch| {
future_pipe::server::completed(move ch, blk());
}))
let (chan, port) = future_pipe::init();

let chan = ~mut Some(move chan);
do task::spawn |move blk, move chan| {
let chan = option::swap_unwrap(&mut *chan);
future_pipe::client::completed(move chan, blk());
}

return from_port(move port);
}

pub fn get_ref<A>(future: &r/Future<A>) -> &r/A {
Expand Down Expand Up @@ -163,7 +169,7 @@ pub fn with<A,B>(future: &Future<A>, blk: fn((&A)) -> B) -> B {
}

proto! future_pipe (
waiting:recv<T:Send> {
waiting:send<T:Send> {
completed(T) -> !
}
)
Expand All @@ -178,8 +184,8 @@ pub mod test {

#[test]
pub fn test_from_port() {
let (po, ch) = future_pipe::init();
future_pipe::server::completed(move ch, ~"whale");
let (ch, po) = future_pipe::init();
future_pipe::client::completed(move ch, ~"whale");
let f = from_port(move po);
assert get(&f) == ~"whale";
}
Expand Down