async fn build_async<F, T>(timeout: Duration, sync_code: F) -> Result<T>
where
  F: FnOnce() -> T + Send + 'static,
  T: Send + std::fmt::Debug + 'static,
{
  let (tx, rx) = channel::<T>();

  thread::spawn(move || {
    // TODO: if the sync_code panics this
    //       call will wait forever
    let r = sync_code();
    if let Err(e) = tx.send(r) {
      tracing::warn!(?e, "build_async: could not oneshot")
    }
  });

  Ok(tokio::time::timeout(timeout, rx).await??)
}
/// Helper to convert sync code to async using an oneshot channel
/// uses a timeout to ensure continuation of executing in case
/// sync_code would panic
Helper to convert sync code to async using an oneshot channel
uses a timeout to ensure continuation of executing in case
sync_code would panic
Helper to convert sync code to async using an oneshot channel uses a timeout to ensure continuation of executing in case sync_code would panic
async fn build_async<F, T>(timeout: Duration, sync_code: F) -> Result<T>
where
  F: FnOnce() -> T + Send + 'static,
  T: Send + std::fmt::Debug + 'static,
{
  let (tx, rx) = channel::<T>();
  thread::spawn(move || {
    // TODO: if the sync_code panics this
    //       call will wait forever
    let r = sync_code();
    if let Err(e) = tx.send(r) {
      tracing::warn!(?e, "build_async: could not oneshot")
    }
  });
  Ok(tokio::time::timeout(timeout, rx).await??)
}
async fn build_async < F , T > ( timeout : Duration , sync_code : F ) -> Result < T > where F : FnOnce ( ) -> T + Send + ' static , T : Send + std :: fmt :: Debug + ' static , { let ( tx , rx ) = channel :: < T > ( ) ; thread :: spawn ( move | | { // TODO: if the sync_code panics this //       call will wait forever let r = sync_code ( ) ; if let Err ( e ) = tx . send ( r ) { tracing :: warn ! ( e " " ) } } ) ; Ok ( tokio :: time :: timeout ( timeout , rx ) . await ? ? ) }
Helper to convert sync code to async using an oneshot channel
uses a timeout to ensure continuation of executing in case
sync_code would panic
Helper to convert sync code to async using an oneshot channel uses a timeout to ensure continuation of executing in case sync_code would panic
timeout
Duration
sync_code
F
timeout
Duration
sync_code
F