| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#, timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#}; |
| 2 | |
| 3 | use crossbeam_channelrust-analyzer cargo crossbeam-channel 0.5.16 crate/::{unboundedrust-analyzer cargo crossbeam-channel 0.5.16 channel/unbounded()., Receiverrust-analyzer cargo crossbeam-channel 0.5.16 channel/Receiver#, Selectrust-analyzer cargo crossbeam-channel 0.5.16 select/Select#, Senderrust-analyzer cargo crossbeam-channel 0.5.16 channel/Sender#}; |
| 4 | |
| 5 | use craterust-analyzer cargo threadfin 0.1.2 crate/::taskrust-analyzer cargo threadfin 0.1.2 task/::{Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#, RunResultrust-analyzer cargo threadfin 0.1.2 task/RunResult#}; |
| 6 | |
| 7 | /// A type which receives notifications from a worker. |
| 8 | pub(craterust-analyzer cargo threadfin 0.1.2 crate/) trait Listenerrust-analyzer cargo threadfin 0.1.2 worker/Listener# { |
| 9 | fn on_task_startedrust-analyzer cargo threadfin 0.1.2 worker/Listener#on_task_started().(&mut self) {} |
| 10 | |
| 11 | fn on_task_completedrust-analyzer cargo threadfin 0.1.2 worker/Listener#on_task_completed().(&mut self, _panicked: bool) {} |
| 12 | |
| 13 | fn on_idlerust-analyzer cargo threadfin 0.1.2 worker/Listener#on_idle().(&mut self) -> bool { |
| 14 | true |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | /// A worker thread which belongs to a thread pool and executes tasks. |
| 19 | pub(craterust-analyzer cargo threadfin 0.1.2 crate/) struct Workerrust-analyzer cargo threadfin 0.1.2 worker/Worker#<L: Listenerrust-analyzer cargo threadfin 0.1.2 worker/Listener#> { |
| 20 | keep_aliverust-analyzer cargo threadfin 0.1.2 worker/Worker#keep_alive.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 21 | |
| 22 | concurrency_limitrust-analyzer cargo threadfin 0.1.2 worker/Worker#concurrency_limit.: usize, |
| 23 | |
| 24 | /// An initial task this worker should be run before polling for new work. |
| 25 | initial_taskrust-analyzer cargo threadfin 0.1.2 worker/Worker#initial_task.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 26 | |
| 27 | /// Pending tasks being run by this worker. Any task that yields without |
| 28 | /// being immediately complete is moved to this location to be polled again. |
| 29 | pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<usize, Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 30 | |
| 31 | /// Queue of new tasks to run. The worker pulls more tasks from this queue |
| 32 | /// when idle. |
| 33 | queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#queue.: Receiverrust-analyzer cargo crossbeam-channel 0.5.16 channel/Receiver#<Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 34 | immediate_queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#immediate_queue.: Receiverrust-analyzer cargo crossbeam-channel 0.5.16 channel/Receiver#<Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 35 | |
| 36 | /// Channel used to receive notifications from wakers for pending tasks. |
| 37 | wake_notificationsrust-analyzer cargo threadfin 0.1.2 worker/Worker#wake_notifications.: (Senderrust-analyzer cargo crossbeam-channel 0.5.16 channel/Sender#<usize>, Receiverrust-analyzer cargo crossbeam-channel 0.5.16 channel/Receiver#<usize>), |
| 38 | |
| 39 | /// Set to true when the worker is running and wants to consume more work. |
| 40 | activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active.: bool, |
| 41 | |
| 42 | /// Receiver of various worker events. |
| 43 | listenerrust-analyzer cargo threadfin 0.1.2 worker/Worker#listener.: L, |
| 44 | } |
| 45 | |
| 46 | impl<L: Listenerrust-analyzer cargo threadfin 0.1.2 worker/Listener#> Workerrust-analyzer cargo threadfin 0.1.2 worker/Worker#<L> { |
| 47 | /// Create a new worker. |
| 48 | pub(craterust-analyzer cargo threadfin 0.1.2 crate/) fn newrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]new().( |
| 49 | initial_task: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 50 | queue: Receiverrust-analyzer cargo crossbeam-channel 0.5.16 channel/Receiver#<Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 51 | immediate_queue: Receiverrust-analyzer cargo crossbeam-channel 0.5.16 channel/Receiver#<Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#>, |
| 52 | concurrency_limit: usize, |
| 53 | keep_alive: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, |
| 54 | listener: L, |
| 55 | ) -> Selfrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`] { |
| 56 | Selfrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`] { |
| 57 | keep_aliverust-analyzer cargo threadfin 0.1.2 worker/Worker#keep_alive., |
| 58 | concurrency_limitrust-analyzer cargo threadfin 0.1.2 worker/Worker#concurrency_limit., |
| 59 | initial_taskrust-analyzer cargo threadfin 0.1.2 worker/Worker#initial_task., |
| 60 | pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(), |
| 61 | queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#queue., |
| 62 | immediate_queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#immediate_queue., |
| 63 | wake_notificationsrust-analyzer cargo threadfin 0.1.2 worker/Worker#wake_notifications.: unboundedrust-analyzer cargo crossbeam-channel 0.5.16 channel/unbounded().(), |
| 64 | activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active.: false, |
| 65 | listenerrust-analyzer cargo threadfin 0.1.2 worker/Worker#listener., |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /// Run the worker on the current thread until the work queue is closed. |
| 70 | pub(craterust-analyzer cargo threadfin 0.1.2 crate/) fn runrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]run().(mut self) { |
| 71 | self.activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active. = true; |
| 72 | |
| 73 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(coroutine) = self.initial_taskrust-analyzer cargo threadfin 0.1.2 worker/Worker#initial_task..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().() { |
| 74 | self.run_now_or_reschedulerust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]run_now_or_reschedule().(coroutine); |
| 75 | } |
| 76 | |
| 77 | // Main worker loop, keep running until the pool shuts down and pending |
| 78 | // tasks complete. |
| 79 | while self.activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active. || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().() { |
| 80 | match self.poll_workrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]poll_work().() { |
| 81 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Workrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Work#(coroutine) => self.run_now_or_reschedulerust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]run_now_or_reschedule().(coroutine), |
| 82 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Wakerust-analyzer cargo threadfin 0.1.2 worker/PollResult#Wake#(id) => self.run_pending_by_idrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]run_pending_by_id().(id), |
| 83 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::ShutDownrust-analyzer cargo threadfin 0.1.2 worker/PollResult#ShutDown# => self.activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active. = false, |
| 84 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Timeoutrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Timeout# => { |
| 85 | // If this worker doesn't have an pending tasks, then we can |
| 86 | // potentially shut down the worker due to inactivity. |
| 87 | if self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().() { |
| 88 | // If the listener tells us we ought to shut down, then |
| 89 | // do so. |
| 90 | if self.listenerrust-analyzer cargo threadfin 0.1.2 worker/Worker#listener..on_idlerust-analyzer cargo threadfin 0.1.2 worker/Listener#on_idle().() { |
| 91 | self.activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active. = false; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /// Poll for the next work item the worker should work on. |
| 100 | fn poll_workrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]poll_work().(&mut self) -> PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult# { |
| 101 | let mut queue_id = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 102 | let mut immediate_queue_id = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 103 | let mut wake_id = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 104 | let mut select = Selectrust-analyzer cargo crossbeam-channel 0.5.16 select/Select#::newrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`Select<'a>`]new().(); |
| 105 | |
| 106 | // As long as we haven't reached our concurrency limit, poll for |
| 107 | // additional work. |
| 108 | if self.activerust-analyzer cargo threadfin 0.1.2 worker/Worker#active. && self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().self.concurrency_limitrust-analyzer cargo threadfin 0.1.2 worker/Worker#concurrency_limit. { |
| 109 | queue_id = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(select.recvrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`Select<'a>`]recv().(&self.queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#queue.)); |
| 110 | immediate_queue_id = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(select.recvrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`Select<'a>`]recv().(&self.immediate_queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#immediate_queue.)); |
| 111 | } |
| 112 | |
| 113 | // If we have pending tasks, poll for waker notifications as well. |
| 114 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..is_emptyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]is_empty().() { |
| 115 | wake_id = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(select.recvrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`Select<'a>`]recv().(&self.wake_notificationsrust-analyzer cargo threadfin 0.1.2 worker/Worker#wake_notifications..1)); |
| 116 | } |
| 117 | |
| 118 | match select.select_timeoutrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`Select<'a>`]select_timeout().(self.keep_aliverust-analyzer cargo threadfin 0.1.2 worker/Worker#keep_alive.) { |
| 119 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(op) if Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(op.indexrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`SelectedOperation<'_>`]index().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().queue_id => { |
| 120 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(coroutine) = op.recvrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`SelectedOperation<'_>`]recv().(&self.queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#queue.) { |
| 121 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Workrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Work#(coroutine) |
| 122 | } else { |
| 123 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::ShutDownrust-analyzer cargo threadfin 0.1.2 worker/PollResult#ShutDown# |
| 124 | } |
| 125 | } |
| 126 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(op) if Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(op.indexrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`SelectedOperation<'_>`]index().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().immediate_queue_id => { |
| 127 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(coroutine) = op.recvrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`SelectedOperation<'_>`]recv().(&self.immediate_queuerust-analyzer cargo threadfin 0.1.2 worker/Worker#immediate_queue.) { |
| 128 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Workrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Work#(coroutine) |
| 129 | } else { |
| 130 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::ShutDownrust-analyzer cargo threadfin 0.1.2 worker/PollResult#ShutDown# |
| 131 | } |
| 132 | } |
| 133 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(op) if Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(op.indexrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`SelectedOperation<'_>`]index().()) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().wake_id => { |
| 134 | PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Wakerust-analyzer cargo threadfin 0.1.2 worker/PollResult#Wake#(op.recvrust-analyzer cargo crossbeam-channel 0.5.16 select/impl#[`SelectedOperation<'_>`]recv().(&self.wake_notificationsrust-analyzer cargo threadfin 0.1.2 worker/Worker#wake_notifications..1).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 135 | } |
| 136 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!(), |
| 137 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult#::Timeoutrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Timeout#, |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | fn run_now_or_reschedulerust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]run_now_or_reschedule().(&mut self, mut coroutine: Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#) { |
| 142 | // If it is possible for this task to yield, we need to prepare a new |
| 143 | // waker to receive notifications with. |
| 144 | if coroutine.might_yieldrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]might_yield().() { |
| 145 | let sender = self.wake_notificationsrust-analyzer cargo threadfin 0.1.2 worker/Worker#wake_notifications..0.clonerust-analyzer cargo crossbeam-channel 0.5.16 channel/impl#[`Sender<T>`][Clone]clone().(); |
| 146 | let coroutine_addr = coroutine.addrrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]addr().(); |
| 147 | |
| 148 | coroutine.set_wakerrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]set_waker().(waker_fnrust-analyzer cargo waker-fn 1.2.0 crate/::waker_fnrust-analyzer cargo waker-fn 1.2.0 waker_fn().(move || { |
| 149 | let _ = sender.sendrust-analyzer cargo crossbeam-channel 0.5.16 channel/impl#[`Sender<T>`]send().(coroutine_addr); |
| 150 | })); |
| 151 | } |
| 152 | |
| 153 | self.listenerrust-analyzer cargo threadfin 0.1.2 worker/Worker#listener..on_task_startedrust-analyzer cargo threadfin 0.1.2 worker/Listener#on_task_started().(); |
| 154 | |
| 155 | if let RunResultrust-analyzer cargo threadfin 0.1.2 task/RunResult#::Completerust-analyzer cargo threadfin 0.1.2 task/RunResult#Complete# { |
| 156 | panickedrust-analyzer cargo threadfin 0.1.2 task/RunResult#Complete#panicked., |
| 157 | } = coroutine.runrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]run().() |
| 158 | { |
| 159 | self.listenerrust-analyzer cargo threadfin 0.1.2 worker/Worker#listener..on_task_completedrust-analyzer cargo threadfin 0.1.2 worker/Listener#on_task_completed().(panicked); |
| 160 | coroutine.completerust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]complete().(); |
| 161 | } else { |
| 162 | // This should never happen if the task promised not to yield! |
| 163 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(coroutine.might_yieldrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]might_yield().()); |
| 164 | |
| 165 | // Task yielded, so we'll need to reschedule the task to be polled |
| 166 | // again when its waker is called. We do this by storing the future |
| 167 | // in a collection local to this worker where we can retrieve it |
| 168 | // again. |
| 169 | // |
| 170 | // The benefit of doing it this way instead of sending the future |
| 171 | // back through the queue is that the future gets executed (almost) |
| 172 | // immediately once it wakes instead of being put behind a queue of |
| 173 | // _new_ tasks. |
| 174 | self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(coroutine.addrrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]addr().(), coroutine); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | fn run_pending_by_idrust-analyzer cargo threadfin 0.1.2 worker/impl#[`Worker<L>`]run_pending_by_id().(&mut self, id: usize) { |
| 179 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(coroutine) = self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&id) { |
| 180 | if let RunResultrust-analyzer cargo threadfin 0.1.2 task/RunResult#::Completerust-analyzer cargo threadfin 0.1.2 task/RunResult#Complete# { |
| 181 | panickedrust-analyzer cargo threadfin 0.1.2 task/RunResult#Complete#panicked., |
| 182 | } = coroutine.runrust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]run().() |
| 183 | { |
| 184 | self.listenerrust-analyzer cargo threadfin 0.1.2 worker/Worker#listener..on_task_completedrust-analyzer cargo threadfin 0.1.2 worker/Listener#on_task_completed().(panicked); |
| 185 | |
| 186 | // Task is complete, we can de-allocate it and complete it. |
| 187 | self.pending_tasksrust-analyzer cargo threadfin 0.1.2 worker/Worker#pending_tasks..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(&id).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().completerust-analyzer cargo threadfin 0.1.2 task/impl#[Coroutine]complete().(); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | enum PollResultrust-analyzer cargo threadfin 0.1.2 worker/PollResult# { |
| 194 | /// New work has arrived for this worker. |
| 195 | Workrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Work#(Coroutinerust-analyzer cargo threadfin 0.1.2 task/Coroutine#), |
| 196 | |
| 197 | /// An existing pending task has woken. |
| 198 | Wakerust-analyzer cargo threadfin 0.1.2 worker/PollResult#Wake#(usize), |
| 199 | |
| 200 | /// No activity occurred within the time limit. |
| 201 | Timeoutrust-analyzer cargo threadfin 0.1.2 worker/PollResult#Timeout#, |
| 202 | |
| 203 | /// The thread pool has been shut down. |
| 204 | ShutDownrust-analyzer cargo threadfin 0.1.2 worker/PollResult#ShutDown#, |
| 205 | } |