std: Expose that LocalIo may not always be available

It is not the case that all programs will always be able to acquire an instance
of the LocalIo borrow, so this commit exposes this limitation by returning
Option<LocalIo> from LocalIo::borrow().

At the same time, a helper method LocalIo::maybe_raise() has been added in order
to encapsulate the functionality of raising on io_error if there is on local I/O
available.
This commit is contained in:
Alex Crichton
2013-12-12 17:30:41 -08:00
parent a55c57284d
commit 4538369566
11 changed files with 118 additions and 176 deletions

View File

@@ -119,19 +119,17 @@ impl Process {
/// Creates a new pipe initialized, but not bound to any particular
/// source/destination
pub fn new(config: ProcessConfig) -> Option<Process> {
let mut io = LocalIo::borrow();
match io.get().spawn(config) {
Ok((p, io)) => Some(Process{
handle: p,
io: io.move_iter().map(|p|
p.map(|p| io::PipeStream::new(p))
).collect()
}),
Err(ioerr) => {
io_error::cond.raise(ioerr);
None
}
}
let mut config = Some(config);
LocalIo::maybe_raise(|io| {
io.spawn(config.take_unwrap()).map(|(p, io)| {
Process {
handle: p,
io: io.move_iter().map(|p| {
p.map(|p| io::PipeStream::new(p))
}).collect()
}
})
})
}
/// Returns the process id of this child process