Struct Runtime

Source
pub struct Runtime { /* private fields */ }
Expand description

The async runtime of compio. It is a thread local runtime, and cannot be sent to other threads.

Implementations§

Source§

impl Runtime

Source

pub fn new() -> Result<Self>

Create Runtime with default config.

Source

pub fn builder() -> RuntimeBuilder

Create a builder for Runtime.

Source

pub fn try_with_current<T, F: FnOnce(&Self) -> T>(f: F) -> Result<T, F>

Try to perform a function on the current runtime, and if no runtime is running, return the function back.

Source

pub fn with_current<T, F: FnOnce(&Self) -> T>(f: F) -> T

Perform a function on the current runtime.

§Panics

This method will panic if there are no running Runtime.

Source

pub fn enter<T, F: FnOnce() -> T>(&self, f: F) -> T

Set this runtime as current runtime, and perform a function in the current scope.

Source

pub unsafe fn spawn_unchecked<F: Future>(&self, future: F) -> Task<F::Output>

Spawns a new asynchronous task, returning a Task for it.

§Safety

The caller should ensure the captured lifetime long enough.

Source

pub fn run(&self) -> bool

Low level API to control the runtime.

Run the scheduled tasks.

The return value indicates whether there are still tasks in the queue.

Source

pub fn block_on<F: Future>(&self, future: F) -> F::Output

Block on the future till it completes.

Source

pub fn spawn<F: Future + 'static>(&self, future: F) -> JoinHandle<F::Output>

Spawns a new asynchronous task, returning a Task for it.

Spawning a task enables the task to execute concurrently to other tasks. There is no guarantee that a spawned task will execute to completion.

Source

pub fn spawn_blocking<T: Send + 'static>( &self, f: impl FnOnce() -> T + Send + 'static, ) -> JoinHandle<T>

Spawns a blocking task in a new thread, and wait for it.

The task will not be cancelled even if the future is dropped.

Source

pub fn attach(&self, fd: RawFd) -> Result<()>

Attach a raw file descriptor/handle/socket to the runtime.

You only need this when authoring your own high-level APIs. High-level resources in this crate are attached automatically.

Source

pub fn submit<T: OpCode + 'static>( &self, op: T, ) -> impl Future<Output = BufResult<usize, T>>

👎Deprecated: use compio::runtime::submit instead

Submit an operation to the runtime.

You only need this when authoring your own OpCode.

It is safe to send the returned future to another runtime and poll it, but the exact behavior is not guaranteed, e.g. it may return pending forever or else.

Source

pub fn submit_with_flags<T: OpCode + 'static>( &self, op: T, ) -> impl Future<Output = (BufResult<usize, T>, u32)>

👎Deprecated: use compio::runtime::submit_with_flags instead

Submit an operation to the runtime.

The difference between Runtime::submit is this method will return the flags

You only need this when authoring your own OpCode.

It is safe to send the returned future to another runtime and poll it, but the exact behavior is not guaranteed, e.g. it may return pending forever or else.

Source

pub fn current_timeout(&self) -> Option<Duration>

Low level API to control the runtime.

Get the timeout value to be passed to Proactor::poll.

Source

pub fn poll(&self)

Low level API to control the runtime.

Poll the inner proactor. It is equal to calling Runtime::poll_with with Runtime::current_timeout.

Source

pub fn poll_with(&self, timeout: Option<Duration>)

Low level API to control the runtime.

Poll the inner proactor with a custom timeout.

Trait Implementations§

Source§

impl AsRawFd for Runtime

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl AsyncExecutor for &Runtime

Available on crate feature criterion only.
Source§

fn block_on<T>(&self, future: impl Future<Output = T>) -> T

Spawn the given future onto this runtime and block until it’s complete, returning the result.
Source§

impl AsyncExecutor for Runtime

Available on crate feature criterion only.
Source§

fn block_on<T>(&self, future: impl Future<Output = T>) -> T

Spawn the given future onto this runtime and block until it’s complete, returning the result.
Source§

impl Drop for Runtime

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Runtime

§

impl !RefUnwindSafe for Runtime

§

impl !Send for Runtime

§

impl !Sync for Runtime

§

impl Unpin for Runtime

§

impl !UnwindSafe for Runtime

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more