message: Factor out internal parts of request creation with `EffectBuilder::create_request_parts`
diff: @@ -454,6 +454,26 @@ impl<REv> EffectBuilder<REv> {
  /// This future is cancellation safe: If it is dropped without being polled, it merely indicates
  /// the original requestor is not longer interested in the result, which will be discarded.
  pub(crate) async fn make_request<T, Q, F>(self, f: F, queue_kind: QueueKind) -> T
  + where
  + T: Send + 'static,
  + Q: Into<REv>,
  + F: FnOnce(Responder<T>) -> Q,
  + {
  + let (event, wait_future) = self.create_request_parts(f);
  +
  + // Schedule the request before awaiting the response.
  + self.event_queue.schedule(event, queue_kind).await;
  + wait_future.await
  + }
  +
  + /// Creates the part necessary to make a request.
  + ///
  + /// A request usually consists of two parts: The request event that needs to be scheduled on the
  + /// reactor queue and associated future that allows waiting for the response. This function
  + /// creates both of them without processing or spawning either.
  + ///
  + /// Usually you will want to call the higher level `make_request` function.
  + pub(crate) fn create_request_parts<T, Q, F>(self, f: F) -> (REv, impl Future<Output = T>)
  where
  T: Send + 'static,
  Q: Into<REv>,
  @@ -467,8 +487,8 @@ impl<REv> EffectBuilder<REv> {
  // Now inject the request event into the event loop.
  let request_event = f(responder).into();
  - self.event_queue.schedule(request_event, queue_kind).await;
  + let fut = async move {
  match receiver.await {
  Ok(value) => value,
  Err(err) => {
  @@ -477,9 +497,9 @@ impl<REv> EffectBuilder<REv> {
  //
  // If it does happen, we pretend nothing happened instead of crashing.
  if self.event_queue.shutdown_flag().is_set() {
  - debug!(%err, ?queue_kind, channel=?type_name::<T>(), "ignoring closed channel due to shutdown")
  + debug!(%err, channel=?type_name::<T>(), "ignoring closed channel due to shutdown")
  } else {
  - error!(%err, ?queue_kind, channel=?type_name::<T>(), "request for channel closed, this may be a bug? \
  + error!(%err, channel=?type_name::<T>(), "request for channel closed, this may be a bug? \
  check if a component is stuck from now on");
  }
  @@ -489,6 +509,9 @@ impl<REv> EffectBuilder<REv> {
  panic!("should never obtain unobtainable semaphore");
  }
  }
  + };
  +
  + (request_event, fut)
  }
  /// Run and end effect immediately.
  