core: fix breakage in TaskBuilder.future_result

the actual "fix" in this change is the chunk that moves
`let x = self.consume()` to after the option dance that results in
the `notify_chan` in TaskBuilder.try()

the rest is cleanup/sense-making of what some of this code is doing (I'm
looking at you, future_result)
This commit is contained in:
Jeff Olson
2012-08-23 22:49:09 -07:00
committed by Brian Anderson
parent a8fc771f20
commit d41af3e002
+15 -7
View File
@@ -366,17 +366,22 @@ fn future_result(blk: fn(+future::Future<TaskResult>)) -> TaskBuilder {
}
// Construct the future and give it to the caller.
let (ch, po) = stream::<Notification>();
let (notify_pipe_ch, notify_pipe_po) = stream::<Notification>();
blk(do future::from_fn {
match po.recv() {
match notify_pipe_po.recv() {
Exit(_, result) => result
}
});
// Reconfigure self to use a notify channel.
TaskBuilder({
opts: { notify_chan: Some(ch),.. self.opts },
opts: {
linked: self.opts.linked,
supervised: self.opts.supervised,
mut notify_chan: Some(notify_pipe_ch),
sched: self.opts.sched
},
can_not_copy: None,
.. *self.consume()
})
@@ -445,12 +450,14 @@ fn add_wrapper(wrapper: fn@(+fn~()) -> fn~()) -> TaskBuilder {
* must be greater than zero.
*/
fn spawn(+f: fn~()) {
let x = self.consume();
let notify_chan = if self.opts.notify_chan == None {
let notify_chan = if self.opts.notify_chan == none {
None
} else {
Some(option::swap_unwrap(&mut self.opts.notify_chan))
let swapped_notify_chan =
option::swap_unwrap(&mut self.opts.notify_chan);
some(swapped_notify_chan)
};
let x = self.consume();
let opts = {
linked: x.opts.linked,
supervised: x.opts.supervised,
@@ -522,7 +529,8 @@ fn try<T: Send>(+f: fn~() -> T) -> Result<T,()> {
let ch = comm::Chan(po);
let mut result = None;
do self.future_result(|+r| { result = Some(r); }).spawn {
let fr_task_builder = self.future_result(|+r| { result = Some(r); });
do fr_task_builder.spawn {
comm::send(ch, f());
}
match future::get(&option::unwrap(result)) {