| 91 | } |
| 92 | |
| 93 | fn finalize_callable_outcome( |
| 94 | background: &CallableTask, |
| 95 | out_channel: Option<Channel>, |
| 96 | outcome: CallableOutcome, |
| 97 | ) { |
| 98 | match outcome { |
| 99 | CallableOutcome::Cancelled => {} |
| 100 | CallableOutcome::Failed(message) => { |
| 101 | if !background.is_done() { |
| 102 | background.fail(message); |
| 103 | } |
| 104 | } |
| 105 | CallableOutcome::Ready { |
| 106 | value, |
| 107 | delivery_buffer, |
| 108 | } => { |
| 109 | if background.is_done() { |
| 110 | return; |
| 111 | } |
| 112 | if let Some(channel) = out_channel { |
| 113 | match channel.send(delivery_buffer.expect("buffer required for delivery")) { |
| 114 | Ok(()) => background.complete(value), |
| 115 | Err(err) => background.fail(err.to_string()), |
| 116 | } |
| 117 | } else { |
| 118 | background.complete(value); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /// The runtime module exposed to Python. |
| 125 | #[pyclass(name = "_RuntimeModule")] |