[][src]Struct glommio::prelude::LocalExecutor

pub struct LocalExecutor { /* fields omitted */ }

Single-threaded executor.

The executor can only be run on the thread that created it.

Examples

use glommio::LocalExecutor;

let local_ex = LocalExecutor::make_default();

local_ex.run(async {
    println!("Hello world!");
});

Implementations

impl LocalExecutor[src]

pub fn make_default() -> LocalExecutor[src]

Spawns a single-threaded executor with default settings on the current thread.

This will create a executor using default parameters of LocalExecutorBuilder, if you want to further customize it, use this API instead.

Panics

Panics if creating the executor fails; use LocalExecutorBuilder::make to recover from such errors.

Examples

use glommio::LocalExecutor;

let local_ex = LocalExecutor::make_default();

pub fn id(&self) -> usize[src]

Returns a unique identifier for this Executor.

Examples

use glommio::LocalExecutor;

let local_ex = LocalExecutor::make_default();
println!("My ID: {}", local_ex.id());

pub fn create_task_queue<S>(
    &self,
    shares: Shares,
    latency: Latency,
    name: S
) -> TaskQueueHandle where
    S: Into<String>, 
[src]

Creates a task queue in the executor.

Returns an opaque handler that can later be used to launch tasks into that queue with spawn_into

Examples

use std::time::Duration;
use glommio::{LocalExecutor, Latency, Shares};

let local_ex = LocalExecutor::make_default();

let task_queue = local_ex.create_task_queue(Shares::default(), Latency::Matters(Duration::from_secs(1)), "my_tq");
let task = local_ex.spawn_into(async {
    println!("Hello world");
}, task_queue).expect("failed to spawn task");

pub fn remove_task_queue(
    &self,
    handle: TaskQueueHandle
) -> Result<(), Box<dyn Error>>
[src]

Removes a task queue.

The task queue cannot be removed if there are still pending tasks.

pub fn spawn<T: 'static>(
    &self,
    future: impl Future<Output = T> + 'static
) -> Task<T>

Notable traits for Task<T>

impl<T> Future for Task<T> type Output = T;
[src]

Spawns a task onto the executor.

Examples

use glommio::LocalExecutor;

let local_ex = LocalExecutor::make_default();

let task = local_ex.spawn(async {
    println!("Hello world");
});

pub fn spawn_into<T, F>(
    &self,
    future: F,
    handle: TaskQueueHandle
) -> Result<Task<T>, QueueNotFoundError> where
    T: 'static,
    F: Future<Output = T> + 'static, 
[src]

Spawns a task onto the executor, to be run at a particular task queue indicated by the TaskQueueHandle

Examples

use glommio::{LocalExecutor, Shares};

let local_ex = LocalExecutor::make_default();
let handle = local_ex.create_task_queue(Shares::default(), glommio::Latency::NotImportant, "test_queue");

let task = local_ex.spawn_into(async {
    println!("Hello world");
}, handle).expect("failed to spawn task");

pub fn run<T>(&self, future: impl Future<Output = T>) -> T[src]

Runs the executor until the given future completes.

Examples

use glommio::LocalExecutor;

let local_ex = LocalExecutor::make_default();

let task = local_ex.spawn(async { 1 + 2 });
let res = local_ex.run(async { task.await * 2 });

assert_eq!(res, 6);

Trait Implementations

impl Debug for LocalExecutor[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.