Skip to content

Commit

Permalink
Merge pull request #741 from jprendes/async-shim-v3
Browse files Browse the repository at this point in the history
Remove sync wrappers for containerd client
  • Loading branch information
Mossaka authored Nov 21, 2024
2 parents b2bc6e2 + ae5183a commit 69cc945
Show file tree
Hide file tree
Showing 6 changed files with 384 additions and 289 deletions.
26 changes: 26 additions & 0 deletions crates/containerd-shim-wasm/src/sandbox/async_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#![cfg_attr(windows, allow(dead_code))] // this is currently used only for linux

use std::future::Future;

thread_local! {
// A thread local runtime that can be used to run futures to completion.
// It is a current_thread runtime so that it doesn't spawn new threads.
// It is thread local as different threads might want to run futures concurrently.
static RUNTIME: tokio::runtime::Runtime = {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
};
}

pub trait AmbientRuntime: Future {
fn block_on(self) -> Self::Output
where
Self: Sized,
{
RUNTIME.with(|runtime| runtime.block_on(self))
}
}

impl<F: Future> AmbientRuntime for F {}
Loading

0 comments on commit 69cc945

Please sign in to comment.