Revamp TaskBuilder API
This patch consolidates and cleans up the task spawning APIs: * Removes the problematic `future_result` method from `std::task::TaskBuilder`, and adds a `try_future` that both spawns the task and returns a future representing its eventual result (or failure). * Removes the public `opts` field from `TaskBuilder`, instead adding appropriate builder methods to configure the task. * Adds extension traits to libgreen and libnative that add methods to `TaskBuilder` for spawning the task as a green or native thread. Previously, there was no way to benefit from the `TaskBuilder` functionality and also set the scheduler to spawn within. With this change, all task spawning scenarios are supported through the `TaskBuilder` interface. Closes #3725. [breaking-change]
This commit is contained in:
parent
8e9e17d188
commit
a23511a65d
5 changed files with 619 additions and 420 deletions
26
src/test/run-pass/task-stderr.rs
Normal file
26
src/test/run-pass/task-stderr.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::io::{ChanReader, ChanWriter};
|
||||
use std::task::build;
|
||||
|
||||
fn main() {
|
||||
let (tx, rx) = channel();
|
||||
let mut reader = ChanReader::new(rx);
|
||||
let stderr = ChanWriter::new(tx);
|
||||
|
||||
let res = build().stderr(box stderr as Box<Writer + Send>).try(proc() -> () {
|
||||
fail!("Hello, world!")
|
||||
});
|
||||
assert!(res.is_err());
|
||||
|
||||
let output = reader.read_to_str().unwrap();
|
||||
assert!(output.as_slice().contains("Hello, world!"));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue