core: Use PortOne instead of Future in future_result
This commit is contained in:
parent
f6d2a71436
commit
3e4b2bd2b2
15 changed files with 21 additions and 23 deletions
|
@ -642,7 +642,7 @@ pub mod tests {
|
||||||
// Have to get rid of our reference before blocking.
|
// Have to get rid of our reference before blocking.
|
||||||
{ let _x = move x; } // FIXME(#3161) util::ignore doesn't work here
|
{ let _x = move x; } // FIXME(#3161) util::ignore doesn't work here
|
||||||
let res = option::swap_unwrap(&mut res);
|
let res = option::swap_unwrap(&mut res);
|
||||||
future::get(&res);
|
res.recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||||
|
@ -657,7 +657,7 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
assert unwrap_exclusive(move x) == ~~"hello";
|
assert unwrap_exclusive(move x) == ~~"hello";
|
||||||
let res = option::swap_unwrap(&mut res);
|
let res = option::swap_unwrap(&mut res);
|
||||||
future::get(&res);
|
res.recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] #[ignore(cfg(windows))]
|
#[test] #[ignore(cfg(windows))]
|
||||||
|
|
|
@ -314,7 +314,7 @@ impl TaskBuilder {
|
||||||
* # Failure
|
* # Failure
|
||||||
* Fails if a future_result was already set for this task.
|
* Fails if a future_result was already set for this task.
|
||||||
*/
|
*/
|
||||||
fn future_result(blk: fn(v: future::Future<TaskResult>)) -> TaskBuilder {
|
fn future_result(blk: fn(v: Port<TaskResult>)) -> TaskBuilder {
|
||||||
// FIXME (#3725): Once linked failure and notification are
|
// FIXME (#3725): Once linked failure and notification are
|
||||||
// handled in the library, I can imagine implementing this by just
|
// handled in the library, I can imagine implementing this by just
|
||||||
// registering an arbitrary number of task::on_exit handlers and
|
// registering an arbitrary number of task::on_exit handlers and
|
||||||
|
@ -327,9 +327,7 @@ impl TaskBuilder {
|
||||||
// Construct the future and give it to the caller.
|
// Construct the future and give it to the caller.
|
||||||
let (notify_pipe_ch, notify_pipe_po) = stream::<TaskResult>();
|
let (notify_pipe_ch, notify_pipe_po) = stream::<TaskResult>();
|
||||||
|
|
||||||
blk(do future::from_fn |move notify_pipe_po| {
|
blk(move notify_pipe_po);
|
||||||
notify_pipe_po.recv()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Reconfigure self to use a notify channel.
|
// Reconfigure self to use a notify channel.
|
||||||
TaskBuilder({
|
TaskBuilder({
|
||||||
|
@ -482,7 +480,7 @@ impl TaskBuilder {
|
||||||
do fr_task_builder.spawn |move f| {
|
do fr_task_builder.spawn |move f| {
|
||||||
comm::send(ch, f());
|
comm::send(ch, f());
|
||||||
}
|
}
|
||||||
match future::get(&option::unwrap(move result)) {
|
match option::unwrap(move result).recv() {
|
||||||
Success => result::Ok(comm::recv(po)),
|
Success => result::Ok(comm::recv(po)),
|
||||||
Failure => result::Err(())
|
Failure => result::Err(())
|
||||||
}
|
}
|
||||||
|
@ -899,14 +897,14 @@ fn test_add_wrapper() {
|
||||||
fn test_future_result() {
|
fn test_future_result() {
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
do task().future_result(|+r| { result = Some(move r); }).spawn { }
|
do task().future_result(|+r| { result = Some(move r); }).spawn { }
|
||||||
assert future::get(&option::unwrap(move result)) == Success;
|
assert option::unwrap(move result).recv() == Success;
|
||||||
|
|
||||||
result = None;
|
result = None;
|
||||||
do task().future_result(|+r|
|
do task().future_result(|+r|
|
||||||
{ result = Some(move r); }).unlinked().spawn {
|
{ result = Some(move r); }).unlinked().spawn {
|
||||||
fail;
|
fail;
|
||||||
}
|
}
|
||||||
assert future::get(&option::unwrap(move result)) == Failure;
|
assert option::unwrap(move result).recv() == Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] #[should_fail] #[ignore(cfg(windows))]
|
#[test] #[should_fail] #[ignore(cfg(windows))]
|
||||||
|
|
|
@ -651,7 +651,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for children to pass their asserts
|
// Wait for children to pass their asserts
|
||||||
for vec::each(children) |r| { future::get(r); }
|
for vec::each(children) |r| { r.recv(); }
|
||||||
|
|
||||||
// Wait for writer to finish
|
// Wait for writer to finish
|
||||||
p.recv();
|
p.recv();
|
||||||
|
|
|
@ -391,7 +391,7 @@ fn run_test(test: TestDesc, monitor_ch: comm::Chan<MonitorMsg>) {
|
||||||
task::task().unlinked().future_result(|+r| {
|
task::task().unlinked().future_result(|+r| {
|
||||||
result_future = Some(move r);
|
result_future = Some(move r);
|
||||||
}).spawn(move testfn);
|
}).spawn(move testfn);
|
||||||
let task_result = future::get(&option::unwrap(move result_future));
|
let task_result = option::unwrap(move result_future).recv();
|
||||||
let test_result = calc_result(&test, task_result == task::Success);
|
let test_result = calc_result(&test, task_result == task::Success);
|
||||||
comm::send(monitor_ch, (copy test, test_result));
|
comm::send(monitor_ch, (copy test, test_result));
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,7 +74,7 @@ fn run(args: &[~str]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for vec::each(worker_results) |r| {
|
for vec::each(worker_results) |r| {
|
||||||
future::get(r);
|
r.recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
//error!("sending stop message");
|
//error!("sending stop message");
|
||||||
|
|
|
@ -71,7 +71,7 @@ fn run(args: &[~str]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for vec::each(worker_results) |r| {
|
for vec::each(worker_results) |r| {
|
||||||
future::get(r);
|
r.recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
//error!("sending stop message");
|
//error!("sending stop message");
|
||||||
|
|
|
@ -45,7 +45,7 @@ fn run(args: ~[~str]) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
for vec::each(worker_results) |r| {
|
for vec::each(worker_results) |r| {
|
||||||
future::get(r);
|
r.recv();
|
||||||
}
|
}
|
||||||
comm::send(to_child, stop);
|
comm::send(to_child, stop);
|
||||||
let result = comm::recv(from_child);
|
let result = comm::recv(from_child);
|
||||||
|
|
|
@ -78,7 +78,7 @@ fn stress(num_tasks: int) {
|
||||||
stress_task(i);
|
stress_task(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for results.each |r| { future::get(r); }
|
for results.each |r| { r.recv(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -33,7 +33,7 @@ fn spawn_supervised_blocking(myname: &str, +f: fn~()) {
|
||||||
let mut res = None;
|
let mut res = None;
|
||||||
task::task().future_result(|+r| res = Some(move r)).supervised().spawn(move f);
|
task::task().future_result(|+r| res = Some(move r)).supervised().spawn(move f);
|
||||||
error!("%s group waiting", myname);
|
error!("%s group waiting", myname);
|
||||||
let x = future::get(&option::unwrap(move res));
|
let x = option::unwrap(move res).recv();
|
||||||
assert x == task::Success;
|
assert x == task::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ fn test00() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try joining tasks that have already finished.
|
// Try joining tasks that have already finished.
|
||||||
future::get(&option::unwrap(move result));
|
option::unwrap(move result).recv();
|
||||||
|
|
||||||
debug!("Joined task.");
|
debug!("Joined task.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn test00() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join spawned tasks...
|
// Join spawned tasks...
|
||||||
for results.each |r| { future::get(r); }
|
for results.each |r| { r.recv(); }
|
||||||
|
|
||||||
debug!("Completed: Final number is: ");
|
debug!("Completed: Final number is: ");
|
||||||
log(error, sum);
|
log(error, sum);
|
||||||
|
|
|
@ -30,7 +30,7 @@ fn test00() {
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
future::get(&option::unwrap(move result));
|
option::unwrap(move result).recv();
|
||||||
|
|
||||||
assert (sum == number_of_messages * (number_of_messages - 1) / 2);
|
assert (sum == number_of_messages * (number_of_messages - 1) / 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ fn test00() {
|
||||||
while i < number_of_messages { sum += recv(po); i = i + 1; }
|
while i < number_of_messages { sum += recv(po); i = i + 1; }
|
||||||
}
|
}
|
||||||
|
|
||||||
for results.each |r| { future::get(r); }
|
for results.each |r| { r.recv(); }
|
||||||
|
|
||||||
debug!("Completed: Final number is: ");
|
debug!("Completed: Final number is: ");
|
||||||
assert (sum ==
|
assert (sum ==
|
||||||
|
@ -134,7 +134,7 @@ fn test06() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for results.each |r| { future::get(r); }
|
for results.each |r| { r.recv(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ fn main() {
|
||||||
error!("2");
|
error!("2");
|
||||||
yield();
|
yield();
|
||||||
error!("3");
|
error!("3");
|
||||||
future::get(&option::unwrap(move result));
|
option::unwrap(move result).recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child() {
|
fn child() {
|
||||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
||||||
task::task().future_result(|+r| { result = Some(move r); }).spawn(child);
|
task::task().future_result(|+r| { result = Some(move r); }).spawn(child);
|
||||||
error!("1");
|
error!("1");
|
||||||
yield();
|
yield();
|
||||||
future::get(&option::unwrap(move result));
|
option::unwrap(move result).recv();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn child() { error!("2"); }
|
fn child() { error!("2"); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue