-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #741 from jprendes/async-shim-v3
Remove sync wrappers for containerd client
- Loading branch information
Showing
6 changed files
with
384 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
Oops, something went wrong.