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()
pluspthread_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
- Fiber
Deprecated - WARNING: This api is deprecated due to a number of issues including safety
related ones (See doc-comments in
Fiber::cancel
for details). Usefiber::start
,fiber::defer
and/orfiber::Builder
(choose the one most suitable for you). - Fiber
Attr - 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.
- Join
Handle - An owned permission to join a fiber (block on its termination).
- Latch
- A lock for cooperative multitasking environment
- Latch
Guard - 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§
- Yield
Result - 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_
proc Deprecated - 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_
proc Deprecated - 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.
- LuaJoin
Handle Deprecated - LuaUnit
Join Handle Deprecated - Unit
Join Handle Deprecated