| 1 | //! A futures executor as an event source |
| 2 | //! |
| 3 | //! Only available with the `executor` cargo feature of `calloop`. |
| 4 | //! |
| 5 | //! This executor is intended for light futures, which will be polled as part of your |
| 6 | //! event loop. Such futures may be waiting for IO, or for some external computation on an |
| 7 | //! other thread for example. |
| 8 | //! |
| 9 | //! You can create a new executor using the `executor` function, which creates a pair |
| 10 | //! `(Executor<T>, Scheduler<T>)` to handle futures that all evaluate to type `T`. The |
| 11 | //! executor should be inserted into your event loop, and will yield the return values of |
| 12 | //! the futures as they finish into your callback. The scheduler can be cloned and used |
| 13 | //! to send futures to be executed into the executor. A generic executor can be obtained |
| 14 | //! by choosing `T = ()` and letting futures handle the forwarding of their return values |
| 15 | //! (if any) by their own means. |
| 16 | //! |
| 17 | //! **Note:** The futures must have their own means of being woken up, as this executor is, |
| 18 | //! by itself, not I/O aware. See [`LoopHandle::adapt_io`](crate::LoopHandle#method.adapt_io) |
| 19 | //! for that, or you can use some other mechanism if you prefer. |
| 20 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#, pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/::Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#, syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#}; |
| 21 | |
| 22 | use futures_utilrust-analyzer cargo futures-util 0.3.25 crate/::{ |
| 23 | streamrust-analyzer cargo futures-util 0.3.25 stream/::{FuturesUnorderedrust-analyzer cargo futures-util 0.3.25 stream/futures_unordered/FuturesUnordered#, Streamrust-analyzer cargo futures-core 0.3.25 stream/Stream#}, |
| 24 | taskrust-analyzer cargo futures-util 0.3.25 task/::{waker_refrust-analyzer cargo futures-task 0.3.25 waker_ref/waker_ref()., ArcWakerust-analyzer cargo futures-task 0.3.25 arc_wake/ArcWake#, Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#, LocalFutureObjrust-analyzer cargo futures-task 0.3.25 future_obj/LocalFutureObj#, Pollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll# as FutPollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#}, |
| 25 | }; |
| 26 | |
| 27 | use craterust-analyzer cargo calloop 0.10.5 crate/::{ |
| 28 | sourcesrust-analyzer cargo calloop 0.10.5 sources/::{ |
| 29 | channelrust-analyzer cargo calloop 0.10.5 sources/channel/::{channelrust-analyzer cargo calloop 0.10.5 sources/channel/channel()., Channelrust-analyzer cargo calloop 0.10.5 sources/channel/Channel#, ChannelErrorrust-analyzer cargo calloop 0.10.5 sources/channel/ChannelError#, Eventrust-analyzer cargo calloop 0.10.5 sources/channel/Event#, Senderrust-analyzer cargo calloop 0.10.5 sources/channel/Sender#}, |
| 30 | pingrust-analyzer cargo calloop 0.10.5 sources/ping/::{make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping()., Pingrust-analyzer cargo calloop 0.10.5 sources/ping/Ping#, PingErrorrust-analyzer cargo calloop 0.10.5 sources/ping/PingError#, PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/PingSource#}, |
| 31 | EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource#, |
| 32 | }, |
| 33 | Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 34 | }; |
| 35 | |
| 36 | /// A future executor as an event source |
| 37 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 38 | pub struct Executorrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#<T> { |
| 39 | futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#futures.: FuturesUnorderedrust-analyzer cargo futures-util 0.3.25 stream/futures_unordered/FuturesUnordered#<LocalFutureObjrust-analyzer cargo futures-task 0.3.25 future_obj/LocalFutureObj#<'static, T>>, |
| 40 | new_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#new_futures.: Channelrust-analyzer cargo calloop 0.10.5 sources/channel/Channel#<LocalFutureObjrust-analyzer cargo futures-task 0.3.25 future_obj/LocalFutureObj#<'static, T>>, |
| 41 | ready_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#ready_futures.: PingSourcerust-analyzer cargo calloop 0.10.5 sources/ping/PingSource#, |
| 42 | wakerrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#waker.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<ExecWakerrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker#>, |
| 43 | } |
| 44 | |
| 45 | /// A scheduler to send futures to an executor |
| 46 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 47 | pub struct Schedulerrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler#<T> { |
| 48 | senderrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler#sender.: Senderrust-analyzer cargo calloop 0.10.5 sources/channel/Sender#<LocalFutureObjrust-analyzer cargo futures-task 0.3.25 future_obj/LocalFutureObj#<'static, T>>, |
| 49 | } |
| 50 | |
| 51 | impl<T> Schedulerrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler#<T> { |
| 52 | /// Sends the given future to the executor associated to this scheduler |
| 53 | /// |
| 54 | /// Returns an error if the the executor not longer exists. |
| 55 | pub fn schedulerust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Scheduler<T>`]schedule().<Fut: 'static>(&self, future: Fut) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ExecutorDestroyedrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorDestroyed#> |
| 56 | where |
| 57 | Fut: Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = T>, |
| 58 | { |
| 59 | let obj = LocalFutureObjrust-analyzer cargo futures-task 0.3.25 future_obj/LocalFutureObj#::newrust-analyzer cargo futures-task 0.3.25 future_obj/impl#[`LocalFutureObj<'a, T>`]new().(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(future)); |
| 60 | self.senderrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler#sender..sendrust-analyzer cargo calloop 0.10.5 sources/channel/impl#[`Sender<T>`]send().(obj).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| ExecutorDestroyedrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorDestroyed#) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /// Error generated when trying to schedule a future after the |
| 65 | /// executor was destroyed. |
| 66 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(thiserrorrust-analyzer cargo thiserror 1.0.7 crate/::Errorrust-analyzer cargo thiserror-impl 1.0.7 Error:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 67 | #[error("the executor was destroyed")] |
| 68 | pub struct ExecutorDestroyedrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorDestroyed#; |
| 69 | |
| 70 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 71 | struct ExecWakerrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker# { |
| 72 | pingrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker#ping.: Pingrust-analyzer cargo calloop 0.10.5 sources/ping/Ping#, |
| 73 | } |
| 74 | |
| 75 | impl ArcWakerust-analyzer cargo futures-task 0.3.25 arc_wake/ArcWake# for ExecWakerrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker# { |
| 76 | fn wake_by_refrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[ExecWaker][ArcWake]wake_by_ref().(arc_self: &Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<ExecWakerrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker#>) { |
| 77 | arc_self.pingrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker#ping..pingrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[Ping]ping().(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /// Create a new executor, and its associated scheduler |
| 82 | /// |
| 83 | /// May fail due to OS errors preventing calloop to setup its internal pipes (if your |
| 84 | /// process has reatched its file descriptor limit for example). |
| 85 | pub fn executorrust-analyzer cargo calloop 0.10.5 sources/futures/executor().<T>() -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<(Executorrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#<T>, Schedulerrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler#<T>)> { |
| 86 | let (ping, ready_futures) = make_pingrust-analyzer cargo calloop 0.10.5 sources/ping/make_ping().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 87 | let (sender, new_futures) = channelrust-analyzer cargo calloop 0.10.5 sources/channel/channel().(); |
| 88 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(( |
| 89 | Executorrust-analyzer cargo calloop 0.10.5 sources/futures/Executor# { |
| 90 | futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#futures.: FuturesUnorderedrust-analyzer cargo futures-util 0.3.25 stream/futures_unordered/FuturesUnordered#::newrust-analyzer cargo futures-util 0.3.25 stream/futures_unordered/impl#[`FuturesUnordered<Fut>`]new().(), |
| 91 | new_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#new_futures., |
| 92 | ready_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#ready_futures., |
| 93 | wakerrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#waker.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]new().(ExecWakerrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker# { pingrust-analyzer cargo calloop 0.10.5 sources/futures/ExecWaker#ping. }), |
| 94 | }, |
| 95 | Schedulerrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler# { senderrust-analyzer cargo calloop 0.10.5 sources/futures/Scheduler#sender. }, |
| 96 | )) |
| 97 | } |
| 98 | |
| 99 | impl<T> EventSourcerust-analyzer cargo calloop 0.10.5 sources/EventSource# for Executorrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#<T> { |
| 100 | type Eventrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]Event# = T; |
| 101 | type Metadatarust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]Metadata# = (); |
| 102 | type Retrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]Ret# = (); |
| 103 | type Errorrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]Error# = ExecutorErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#; |
| 104 | |
| 105 | fn process_eventsrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]process_events().<F>( |
| 106 | &mut self, |
| 107 | readiness: Readinessrust-analyzer cargo calloop 0.10.5 sys/Readiness#, |
| 108 | token: Tokenrust-analyzer cargo calloop 0.10.5 sys/Token#, |
| 109 | mut callback: F, |
| 110 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#, Selfrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]::Errorrust-analyzer cargo calloop 0.10.5 sources/EventSource#Error#> |
| 111 | where |
| 112 | F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(T, &mut ()), |
| 113 | { |
| 114 | // fetch all newly inserted futures and push them to the container |
| 115 | let futures = &mut self.futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#futures.; |
| 116 | self.new_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#new_futures. |
| 117 | .process_eventsrust-analyzer cargo calloop 0.10.5 sources/channel/impl#[`Channel<T>`][EventSource]process_events().(readiness, token, |evt, _| { |
| 118 | if let Eventrust-analyzer cargo calloop 0.10.5 sources/channel/Event#::Msgrust-analyzer cargo calloop 0.10.5 sources/channel/Event#Msg#(fut) = evt { |
| 119 | futures.pushrust-analyzer cargo futures-util 0.3.25 stream/futures_unordered/impl#[`FuturesUnordered<Fut>`]push().(fut); |
| 120 | } |
| 121 | }) |
| 122 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ExecutorErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#::NewFutureErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#NewFutureError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 123 | |
| 124 | // process ping events to make it non-ready again |
| 125 | self.ready_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#ready_futures. |
| 126 | .process_eventsrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]process_events().(readiness, token, |(), _| {}) |
| 127 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(ExecutorErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#::WakeErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#WakeError#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 128 | |
| 129 | // advance all available futures as much as possible |
| 130 | let waker = waker_refrust-analyzer cargo futures-task 0.3.25 waker_ref/waker_ref().(&self.wakerrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#waker.); |
| 131 | let mut cx = Contextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/Context#::from_wakerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/wake/impl#[`Context<'a>`]from_waker().(&waker); |
| 132 | |
| 133 | while let FutPollrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#::Readyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core task/poll/Poll#Ready#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ret)) = Pinrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/Pin#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core pin/impl#[`Pin<Ptr>`]new().(&mut self.futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#futures.).poll_nextrust-analyzer cargo futures-util 0.3.25 stream/futures_unordered/impl#[`FuturesUnordered<Fut>`][Stream]poll_next().(&mut cx) { |
| 134 | callback(ret, &mut ()); |
| 135 | } |
| 136 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(PostActionrust-analyzer cargo calloop 0.10.5 sources/PostAction#::Continuerust-analyzer cargo calloop 0.10.5 sources/PostAction#Continue#) |
| 137 | } |
| 138 | |
| 139 | fn registerrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]register().(&mut self, poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 140 | self.new_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#new_futures..registerrust-analyzer cargo calloop 0.10.5 sources/channel/impl#[`Channel<T>`][EventSource]register().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 141 | self.ready_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#ready_futures..registerrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]register().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 142 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 143 | } |
| 144 | |
| 145 | fn reregisterrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]reregister().( |
| 146 | &mut self, |
| 147 | poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#, |
| 148 | token_factory: &mut TokenFactoryrust-analyzer cargo calloop 0.10.5 sys/TokenFactory#, |
| 149 | ) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 150 | self.new_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#new_futures..reregisterrust-analyzer cargo calloop 0.10.5 sources/channel/impl#[`Channel<T>`][EventSource]reregister().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 151 | self.ready_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#ready_futures..reregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]reregister().(poll, token_factory)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 152 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 153 | } |
| 154 | |
| 155 | fn unregisterrust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Executor<T>`][EventSource]unregister().(&mut self, poll: &mut Pollrust-analyzer cargo calloop 0.10.5 sys/Poll#) -> craterust-analyzer cargo calloop 0.10.5 crate/::Resultrust-analyzer cargo calloop 0.10.5 error/Result#<()> { |
| 156 | self.new_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#new_futures..unregisterrust-analyzer cargo calloop 0.10.5 sources/channel/impl#[`Channel<T>`][EventSource]unregister().(poll)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 157 | self.ready_futuresrust-analyzer cargo calloop 0.10.5 sources/futures/Executor#ready_futures..unregisterrust-analyzer cargo calloop 0.10.5 sources/ping/eventfd/impl#[PingSource][EventSource]unregister().(poll)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 158 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /// An error arising from processing events in an async executor event source. |
| 163 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(thiserrorrust-analyzer cargo thiserror 1.0.7 crate/::Errorrust-analyzer cargo thiserror-impl 1.0.7 Error:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 164 | pub enum ExecutorErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError# { |
| 165 | /// Error while reading new futures added via [`Scheduler::schedule()`]. |
| 166 | #[errorrust-analyzer cargo thiserror-impl 1.0.7 error:("error adding new futures")] |
| 167 | NewFutureErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#NewFutureError#(ChannelErrorrust-analyzer cargo calloop 0.10.5 sources/channel/ChannelError#), |
| 168 | |
| 169 | /// Error while processing wake events from existing futures. |
| 170 | #[errorrust-analyzer cargo thiserror-impl 1.0.7 error:("error processing wake events")] |
| 171 | WakeErrorrust-analyzer cargo calloop 0.10.5 sources/futures/ExecutorError#WakeError#(PingErrorrust-analyzer cargo calloop 0.10.5 sources/ping/PingError#), |
| 172 | } |
| 173 | |
| 174 | #[cfg(test)] |
| 175 | mod testsrust-analyzer cargo calloop 0.10.5 sources/futures/tests/ { |
| 176 | use superrust-analyzer cargo calloop 0.10.5 sources/futures/::*; |
| 177 | |
| 178 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 179 | fn readyrust-analyzer cargo calloop 0.10.5 sources/futures/tests/ready().() { |
| 180 | let mut event_loop = craterust-analyzer cargo calloop 0.10.5 crate/::EventLooprust-analyzer cargo calloop 0.10.5 loop_logic/EventLoop#::<u32>::try_newrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]try_new().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 181 | |
| 182 | let handle = event_loop.handlerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]handle().(); |
| 183 | |
| 184 | let (exec, sched) = executorrust-analyzer cargo calloop 0.10.5 sources/futures/executor().::<u32>().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 185 | |
| 186 | handle |
| 187 | .insert_sourcerust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`LoopHandle<'l, Data>`]insert_source().(exec, move |ret, &mut (), got| { |
| 188 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().got = ret; |
| 189 | }) |
| 190 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 191 | |
| 192 | let mut got = 0; |
| 193 | |
| 194 | let fut = async { 42 }; |
| 195 | |
| 196 | event_loop |
| 197 | .dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut got) |
| 198 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 199 | |
| 200 | // the future is not yet inserted, and thus has not yet run |
| 201 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(got, 0); |
| 202 | |
| 203 | sched.schedulerust-analyzer cargo calloop 0.10.5 sources/futures/impl#[`Scheduler<T>`]schedule().(fut).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 204 | |
| 205 | event_loop |
| 206 | .dispatchrust-analyzer cargo calloop 0.10.5 loop_logic/impl#[`EventLoop<'l, Data>`]dispatch().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::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#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.), &mut got) |
| 207 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 208 | |
| 209 | // the future has run |
| 210 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(got, 42); |
| 211 | } |
| 212 | } |