Submits a closure for execution on self and waits until it completes.
(&self, work: F)
| 134 | |
| 135 | /// Submits a closure for execution on self and waits until it completes. |
| 136 | pub fn exec_sync<T, F>(&self, work: F) -> T |
| 137 | where F: Send + FnOnce() -> T, T: Send { |
| 138 | let mut result = None; |
| 139 | { |
| 140 | let result_ref = &mut result; |
| 141 | let work = move || { |
| 142 | *result_ref = Some(work()); |
| 143 | }; |
| 144 | |
| 145 | let mut work = Some(work); |
| 146 | let (context, work) = context_and_sync_function(&mut work); |
| 147 | unsafe { |
| 148 | dispatch_sync_f(self.ptr, context, work); |
| 149 | } |
| 150 | } |
| 151 | // This was set so it's safe to unwrap |
| 152 | result.unwrap() |
| 153 | } |
| 154 | |
| 155 | /// Submits a closure for asynchronous execution on self and returns |
| 156 | /// immediately. |