-
Notifications
You must be signed in to change notification settings - Fork 8
Add WASI support by tokio_wasi #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
f2c63e3
f8493f3
395c868
3a13390
97113c2
f6ff913
5ba912c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| use std::future::Future; | ||
| use std::io; | ||
| use std::marker::PhantomData; | ||
|
|
||
| use once_cell::sync::Lazy; | ||
|
|
||
| static RUNTIME: Lazy<tokio::runtime::Runtime> = Lazy::new(|| { | ||
| tokio::runtime::Builder::new_current_thread() | ||
| .enable_all() | ||
| .build() | ||
| .unwrap() | ||
| }); | ||
|
||
|
|
||
| pub(crate) mod time; | ||
|
|
||
| pub(crate) fn get_default_runtime_size() -> usize { | ||
| 0 | ||
| } | ||
|
|
||
| #[inline(always)] | ||
| pub(super) fn spawn_local<F>(f: F) | ||
| where | ||
| F: Future<Output = ()> + 'static, | ||
| { | ||
| RUNTIME.block_on(async { f.await }) | ||
| } | ||
|
|
||
| #[derive(Debug, Clone, Default)] | ||
| pub(crate) struct Runtime {} | ||
|
|
||
| impl Runtime { | ||
| pub fn new(_size: usize) -> io::Result<Self> { | ||
| Ok(Self {}) | ||
| } | ||
|
|
||
| pub fn spawn_pinned<F, Fut>(&self, create_task: F) | ||
| where | ||
| F: FnOnce() -> Fut, | ||
| F: Send + 'static, | ||
| Fut: Future<Output = ()> + 'static, | ||
| { | ||
| RUNTIME.block_on(async { create_task().await }) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub(crate) struct LocalHandle { | ||
| // This type is not send or sync. | ||
| _marker: PhantomData<*const ()>, | ||
| } | ||
|
|
||
| impl LocalHandle { | ||
| pub fn try_current() -> Option<Self> { | ||
| Some(Self { | ||
| _marker: PhantomData, | ||
| }) | ||
| } | ||
|
|
||
| pub fn current() -> Self { | ||
| Self { | ||
| _marker: PhantomData, | ||
| } | ||
| } | ||
|
|
||
| pub fn spawn_local<F>(&self, f: F) | ||
| where | ||
| F: Future<Output = ()> + 'static, | ||
| { | ||
| RUNTIME.block_on(async { f.await }) | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| use std::future::Future; | ||
| use std::time::Duration; | ||
|
|
||
| use futures::stream::{Stream, StreamExt}; | ||
| use tokio_stream::wrappers::IntervalStream; | ||
|
|
||
| #[inline(always)] | ||
| pub(crate) fn sleep(dur: Duration) -> impl Future<Output = ()> { | ||
| tokio::time::sleep(dur) | ||
| } | ||
|
|
||
| pub(crate) fn interval(dur: Duration) -> impl Stream<Item = ()> { | ||
| IntervalStream::new(tokio::time::interval(dur)).then(|_| async {}) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.