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 fiberstack_size
: specifies the desired stack size for the fiberfunc
: 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>
impl Builder<NoFunc>
sourcepub fn new() -> Self
pub fn new() -> Self
Generates the base configuration for spawning a fiber, from which configuration methods can be chained.
sourcepub fn func<'f, F, T>(self, f: F) -> Builder<F>where
F: FnOnce() -> T + 'f,
pub fn func<'f, F, T>(self, f: F) -> Builder<F>where
F: FnOnce() -> T + 'f,
Sets the callee function for the new fiber.
sourcepub fn func_async<'f, F, T>(self, f: F) -> Builder<impl FnOnce() -> T + 'f>where
F: Future<Output = T> + 'f,
T: 'f,
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§impl<F> Builder<F>
impl<F> Builder<F>
sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Names the fiber-to-be.
The name must not contain null bytes (\0
).
sourcepub fn stack_size(self, stack_size: usize) -> Result<Self>
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,
impl<'f, F, T> Builder<F>where
F: FnOnce() -> T + 'f,
T: 'f,
sourcepub fn start(self) -> Result<JoinHandle<'f, T>>
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.
sourcepub fn defer(self) -> Result<JoinHandle<'f, T>>
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.
sourcepub fn defer_ffi(self) -> Result<JoinHandle<'f, T>>
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.
sourcepub fn defer_lua(self) -> Result<JoinHandle<'f, T>>
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,
impl<F, T> Builder<F>where
F: FnOnce() -> T + 'static,
T: 'static,
sourcepub fn start_non_joinable(self) -> Result<FiberId>
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.
sourcepub fn defer_non_joinable(self) -> Result<Option<FiberId>>
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
returnsfalse
).