mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add a helper for sending a message on task failure
This commit is contained in:
parent
73e2e57535
commit
68cc30c1df
1 changed files with 14 additions and 0 deletions
|
@ -3,9 +3,23 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::task;
|
||||
use std::comm::SharedChan;
|
||||
use std::task::TaskBuilder;
|
||||
|
||||
pub fn spawn_named<S: IntoSendStr>(name: S, f: proc()) {
|
||||
let mut builder = task::task();
|
||||
builder.name(name);
|
||||
builder.spawn(f);
|
||||
}
|
||||
|
||||
/// Arrange to send a particular message to a channel if the task built by
|
||||
/// this `TaskBuilder` fails.
|
||||
pub fn send_on_failure<T: Send>(builder: &mut TaskBuilder, msg: T, dest: SharedChan<T>) {
|
||||
let port = builder.future_result();
|
||||
do spawn {
|
||||
match port.recv() {
|
||||
Ok(()) => (),
|
||||
Err(..) => dest.send(msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue