core: Give future_pipe the same definition as pipes::oneshot
This commit is contained in:
@@ -67,7 +67,7 @@ pub fn from_value<A>(val: A) -> Future<A> {
|
|||||||
Future {state: Forced(~(move val))}
|
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> {
|
Future<A> {
|
||||||
/*!
|
/*!
|
||||||
* Create a future from a port
|
* Create a future from a port
|
||||||
@@ -107,9 +107,15 @@ pub fn spawn<A:Send>(blk: fn~() -> A) -> Future<A> {
|
|||||||
* value of the future.
|
* value of the future.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
from_port(pipes::spawn_service_recv(future_pipe::init, |move blk, ch| {
|
let (chan, port) = future_pipe::init();
|
||||||
future_pipe::server::completed(move ch, blk());
|
|
||||||
}))
|
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 {
|
pub fn get_ref<A>(future: &r/Future<A>) -> &r/A {
|
||||||
@@ -163,7 +169,7 @@ pub fn with<A,B>(future: &Future<A>, blk: fn((&A)) -> B) -> B {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proto! future_pipe (
|
proto! future_pipe (
|
||||||
waiting:recv<T:Send> {
|
waiting:send<T:Send> {
|
||||||
completed(T) -> !
|
completed(T) -> !
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -178,8 +184,8 @@ pub mod test {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_from_port() {
|
pub fn test_from_port() {
|
||||||
let (po, ch) = future_pipe::init();
|
let (ch, po) = future_pipe::init();
|
||||||
future_pipe::server::completed(move ch, ~"whale");
|
future_pipe::client::completed(move ch, ~"whale");
|
||||||
let f = from_port(move po);
|
let f = from_port(move po);
|
||||||
assert get(&f) == ~"whale";
|
assert get(&f) == ~"whale";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user