[−][src]Struct safina::Executor
Implementations
impl Executor
[src]
#[must_use]pub fn default() -> Executor
[src]
Creates a new executor with the name async
and 4 threads.
#[must_use]pub fn new(num_threads: usize) -> Executor
[src]
Creates a new executor with the name async
.
You probably want to use default
instead of this.
#[must_use]pub fn with_name(name: &'static str, num_threads: usize) -> Executor
[src]
pub fn spawn(&self, fut: impl Send + Future<Output = ()> + 'static)
[src]
Adds a task that will execute fut
.
The task runs on any available worker thread.
The task runs until fut
completes or the Executor is dropped.
Returns immediately.
Uses
std::boxed::Box::pin
to make the future
Unpin
.
You can use spawn_unpin
to avoid this allocation.
Example:
let executor = safina_executor::Executor::default(); executor.spawn(async move { an_async_fn().await.unwrap(); });
pub fn spawn_unpin(
&self,
fut: impl Send + Unpin + Future<Output = ()> + 'static
)
[src]
&self,
fut: impl Send + Unpin + Future<Output = ()> + 'static
)
Adds a task that will execute fut
.
The task runs on any available worker thread.
The task runs until fut
completes or the Executor is dropped.
Returns immediately.
Note that fut
must be
Unpin
.
You can use
std::boxed::Box::pin
to make it Unpin. The spawn
function does this for you.
Or use pin_utils::pin_mut
to do it with unsafe code that does not allocate memory.
pub fn block_on<R>(&self, fut: impl Send + Future<Output = R> + 'static) -> R
[src]
Executes the future on the current thread and returns its result. Panics if the future panics.
fut
can call spawn
to create tasks.
Those tasks run on the executor and will continue even after
fut
completes and this call returns.
Uses
std::boxed::Box::pin
to make the future
Unpin
.
You can use block_on_unpin
to avoid this allocation.
let executor = safina_executor::Executor::default(); let result = executor.block_on(async { prepare_request().await?; execute_request().await })?;
pub fn block_on_unpin<R>(
&self,
fut: impl Send + Unpin + Future<Output = R> + 'static
) -> R
[src]
&self,
fut: impl Send + Unpin + Future<Output = R> + 'static
) -> R
Executes the future on the current thread and returns its result. Panics if the future panics.
fut
can call spawn
to create tasks.
Those tasks run on the executor and will continue even after
fut
completes and this call returns.
Note that fut
must be
Unpin
.
You can use
std::boxed::Box::pin
to make it Unpin. The block_on
function does this for you.
Or use pin_utils::pin_mut
to do it with unsafe code that does not allocate memory.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Executor
[src]
impl Send for Executor
[src]
impl Sync for Executor
[src]
impl Unpin for Executor
[src]
impl UnwindSafe for Executor
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,