Module fiber

Source
Expand description

Сooperative multitasking module with optional async runtime.

With the fiber module, you can:

  • create, run and manage fibers,
  • use a synchronization mechanism for fibers, similar to “condition variables” and similar to operating-system functions such as pthread_cond_wait() plus pthread_cond_signal(),
  • spawn a fiber based async runtime.

See also:

Re-exports§

pub use channel::Channel;
pub use channel::RecvError;
pub use channel::RecvTimeout;
pub use channel::SendError;
pub use channel::SendTimeout;
pub use channel::TryRecvError;
pub use channel::TrySendError;
pub use mutex::Mutex;
pub use async::block_on;
pub use safety::*;

Modules§

async
Async runtime based on Tarantool fibers. Also includes sycnhronization primitives and useful traits for working with futures.
channel
mutex
safety

Structs§

Builder
Fiber factory which can be used to configure the properties of the new fiber.
Cond
Conditional variable for cooperative multitasking (fibers).
Context
FiberDeprecated
WARNING: This api is deprecated due to a number of issues including safety related ones (See doc-comments in Fiber::cancel for details). Use fiber::start, fiber::defer and/or fiber::Builder (choose the one most suitable for you).
FiberAttr
Fiber attributes container
Fyber
A helper struct which is used to store information about a fiber being created. It’s only utility is the generic parameter which are associated with it.
JoinHandle
An owned permission to join a fiber (block on its termination).
Latch
A lock for cooperative multitasking environment
LatchGuard
An RAII implementation of a “scoped lock” of a latch. When this structure is dropped (falls out of scope), the lock will be unlocked.
NoFunc
This is a typestate helper type representing the state of a Builder that hasn’t been assigned a fiber function yet.

Enums§

YieldResult
Possible check_yield results.

Constants§

CONTEXT_ALIGNMENT
Alignment of the fiber::Context struct.
CONTEXT_MAGIC
A random number to guard our fiber context from changes by someone else.
CONTEXT_SIZE
Size of the fiber::Context struct.
CONTEXT_VERSION
Current version of the fiber::Context struct. This must be bumped every time it’s definition changes.
FIBER_ID_INVALID
A value of type FiberId which cannot be a valid fiber id.
FIBER_ID_MAX_RESERVED
End of the fiber id range reserved for internal use by tarantool.
FIBER_ID_SCHED
Id of the main fiber, i.e. the first fiber created on the tarantool cord.

Functions§

cancel
Cancel the fiber with the given id.
check_yield
Calls a function and checks whether it yielded.
clock
Equivalent to Instant::now_fiber.
context_is_valid
Makes a best effort attempt to check if the given pointer actually points at a valid instance of Context struct.
csw
Returns number of context switches of the current fiber.
csw_of
Returns number of context switches of the fiber with given id or None if fiber with given id wasn’t found.
defer
Creates a new fiber and schedules it for execution, returning a JoinHandle for it.
defer_async
Async version of defer.
defer_procDeprecated
Creates a new fiber and schedules it for execution, returning a JoinHandle<()> for it.
exists
Returns true if fiber with given id exists.
fiber_yield
Yield control to the scheduler.
id
Returns id of current fiber.
is_cancelled
Check current fiber for cancellation (it must be checked manually).
name
Returns the name of the current fiber.
name_of
Returns the name of the fiber with the given id.
name_raw
Returns the name of the fiber with the given id, or None if fiber wasn’t found. The name is returned as a slice of bytes, because it is allowed to contain nul bytes.
reschedule
Reschedule fiber to end of event loop cycle.
set_cancellable
Make it possible or not possible to wakeup the current fiber immediately when it’s cancelled.
set_name
Sets the name of the current fiber.
set_name_of
Sets the name of the fiber with the given id. Returns false if the fiber wasn’t found, true otherwise.
sleep
Put the current fiber to sleep for at least time seconds.
start
Creates a new fiber and yields execution to it immediately, returning a JoinHandle for the new fiber.
start_async
Async version of start.
start_procDeprecated
Creates a new fiber and yields execution to it immediately, returning a [JoinHandle<()>] for the new fiber.
wakeup
Wakeup the fiber with the given id.
yield
Returns control to the scheduler. Works likewise fiber::sleep(Duration::ZERO) but return error if fiber was canceled by another routine.

Type Aliases§

FiberId
Type alias for a fiber id.
LuaJoinHandleDeprecated
LuaUnitJoinHandleDeprecated
UnitJoinHandleDeprecated