Struct tarantool::fiber::Builder

source ·
pub struct Builder<F> { /* private fields */ }
Expand description

Fiber factory which can be used to configure the properties of the new fiber.

Methods can be chained on it in order to configure it.

The currently supported configurations are:

  • name: specifies an associated name for the fiber
  • stack_size: specifies the desired stack size for the fiber
  • func: specifies the fiber function

The start and defer methods will take ownership of the builder and create a Result to the fiber handle with the given configuration.

The fiber::start, fiber::defer free functions use a Builder with default configuration and unwraps its return value.

Implementations§

source§

impl Builder<NoFunc>

source

pub fn new() -> Self

Generates the base configuration for spawning a fiber, from which configuration methods can be chained.

source

pub fn func<'f, F, T>(self, f: F) -> Builder<F>
where F: FnOnce() -> T + 'f,

Sets the callee function for the new fiber.

source

pub fn func_async<'f, F, T>(self, f: F) -> Builder<impl FnOnce() -> T + 'f>
where F: Future<Output = T> + 'f, T: 'f,

Sets the callee async function for the new fiber.

source

pub fn proc<'f, F>(self, f: F) -> Builder<F>
where F: FnOnce() + 'f,

👎Deprecated: Use Builder::func instead

Sets the callee procedure for the new fiber.

source

pub fn proc_async<'f, F>(self, f: F) -> Builder<impl FnOnce() + 'f>
where F: Future<Output = ()> + 'f,

👎Deprecated: Use Builder::func_async instead

Sets the callee async procedure for the new fiber.

source§

impl<F> Builder<F>

source

pub fn name(self, name: impl Into<String>) -> Self

Names the fiber-to-be.

The name must not contain null bytes (\0).

source

pub fn stack_size(self, stack_size: usize) -> Result<Self>

Sets the size of the stack (in bytes) for the new fiber.

This function performs some runtime tests to validate the given stack size. If stack_size is invalid then Error::Tarantool will be returned.

source§

impl<'f, F, T> Builder<F>
where F: FnOnce() -> T + 'f, T: 'f,

source

pub fn start(self) -> Result<JoinHandle<'f, T>>

Spawns a new joinable fiber with the given configuration.

Returns an error if

  • spawning the fiber failed,
  • fiber name contains a nul byte.

The current fiber performs a yield and the execution is transfered to the new fiber immediately.

Panicking

If JoinHandle::join is not called on the join handle, a panic will happen when the join handle is dropped.

source

pub fn defer(self) -> Result<JoinHandle<'f, T>>

Spawns a new deferred joinable fiber with the given configuration.

NOTE: On older versions of tarantool this will create a lua fiber which is less efficient. You can use ffi::has_fiber_set_ctx to check if your version of tarantool has api needed for this function to work efficiently.

Returns an error if

  • spawning the fiber failed,
  • fiber name contains a nul byte.
Panicking

If JoinHandle::join is not called on the join handle, a panic will happen when the join handle is dropped.

source

pub fn defer_ffi(self) -> Result<JoinHandle<'f, T>>

Spawns a new joinable deferred fiber with the given configuration.

Panicking

This may panic on older version of tarantool. You can use ffi::has_fiber_set_ctx to check if your version of tarantool has the needed api.

Returns an error if

  • spawning the fiber failed,
  • fiber name contains a nul byte.

Consider using Self::defer instead.

source

pub fn defer_lua(self) -> Result<JoinHandle<'f, T>>

Spawns a new joinable deferred fiber with the given configuration using the lua implementation.

This is legacy api and you probably don’t want to use it. This mainly exists for testing.

Consider using Self::defer instead.

source§

impl<F, T> Builder<F>
where F: FnOnce() -> T + 'static, T: 'static,

source

pub fn start_non_joinable(self) -> Result<FiberId>

Spawns a new non-joinable fiber with the given configuration.

Returns the new fiber’s id.

The fiber id can be used for example with wakeup, cancel, exists, csw_of, etc.

Returns an error if

  • spawning the fiber failed,
  • fiber name contains a nul byte,
  • fiber function returns a non zero-sized value.

The current fiber performs a yield and the execution is transfered to the new fiber immediately.

source

pub fn defer_non_joinable(self) -> Result<Option<FiberId>>

Spawns a new deferred non-joinable fiber with the given configuration.

Returns the new fiber’s id, if the corresponding api is supported in current tarantool executable (i.e. has_fiber_id returns true), otherwise returns None.

The fiber id can be used for example with wakeup, cancel, exists, csw_of, etc.

Returns an error if

  • spawning the fiber failed,
  • fiber function returns a non zero-sized value,
  • fiber name contains a nul byte,
  • the necessary api is not supported on current tarantool version (i.e. ffi::has_fiber_set_ctx returns false).

Trait Implementations§

source§

impl<T> Debug for Builder<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder<NoFunc>

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<F> RefUnwindSafe for Builder<F>
where F: RefUnwindSafe,

§

impl<F> !Send for Builder<F>

§

impl<F> !Sync for Builder<F>

§

impl<F> Unpin for Builder<F>
where F: Unpin,

§

impl<F> UnwindSafe for Builder<F>
where F: UnwindSafe,

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, 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.