feat(executor): add multi::Executor
This commit is contained in:
parent
cc21b9baa1
commit
e4280dd381
3 changed files with 38 additions and 1 deletions
|
|
@ -1,3 +1,10 @@
|
||||||
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio")]
|
||||||
|
pub mod multi;
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio")]
|
||||||
pub mod single;
|
pub mod single;
|
||||||
|
|
||||||
#[cfg(not(feature = "tokio"))]
|
#[cfg(not(feature = "tokio"))]
|
||||||
|
|
|
||||||
27
src/executor/multi.rs
Normal file
27
src/executor/multi.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio")]
|
||||||
|
pub struct Executor(tokio::runtime::Runtime);
|
||||||
|
|
||||||
|
#[cfg(feature = "tokio")]
|
||||||
|
impl iced_native::Executor for Executor {
|
||||||
|
fn new() -> Result<Self, iced::futures::io::Error> {
|
||||||
|
Ok(Self(
|
||||||
|
tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.enable_all()
|
||||||
|
.build()?,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||||
|
let _res = self.0.spawn(future);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
||||||
|
let _guard = self.0.enter();
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
#[cfg(feature = "tokio")]
|
#[cfg(feature = "tokio")]
|
||||||
|
|
@ -18,7 +21,7 @@ impl iced_native::Executor for Executor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
fn spawn(&self, future: impl Future<Output = ()> + Send + 'static) {
|
||||||
let _ = self.0.spawn(future);
|
let _res = self.0.spawn(future);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
fn enter<R>(&self, f: impl FnOnce() -> R) -> R {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue