Skip to content

Commit 4406723

Browse files
committed
chore(fiber): add "defer" feature and clarifying comments
- defer functionality is now hidden behind the "defer" feature - added comments explaining which methods do how many yields
1 parent d7ba589 commit 4406723

File tree

4 files changed

+42
-17
lines changed

4 files changed

+42
-17
lines changed

tarantool/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ default = ["net_box"]
5151
net_box = ["lazy_static", "refpool"]
5252
raft_node = ["chrono", "ipnetwork", "net_box", "protobuf", "raft", "rand"]
5353
schema = []
54-
all = ["default", "raft_node", "schema"]
54+
defer = []
55+
all = ["default", "raft_node", "schema", "defer"]
5556

tarantool/src/fiber.rs

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,23 @@ where
286286
/// Spawns a new fiber by taking ownership of the `Builder`, and returns a
287287
/// [`Result`] to its [`JoinHandle`].
288288
///
289+
/// The current fiber performs a **yield** and the execution is transfered
290+
/// to the new fiber immediately.
291+
///
289292
/// See the [`start`] free function for more details.
290293
pub fn start(self) -> Result<C::JoinHandle> {
291294
inner_spawn!(self, immediate)
292295
}
293296

294-
/// Spawns a new deferred fiber by taking ownership of the `Builder`,
295-
/// and returns a [`Result`] to its [`JoinHandle`].
297+
#[cfg(feature = "defer")]
298+
/// Spawns a new deferred fiber by taking ownership of the `Builder`, and
299+
/// returns a [`Result`] to its [`JoinHandle`].
300+
///
301+
/// **NOTE:** In the current implementation the current fiber performs a
302+
/// **yield** to start the newly created fiber and then the new fiber
303+
/// performs another **yield**. This means that the deferred fiber is **not
304+
/// applicable for transactions** (which do not allow any context switches).
305+
/// In the future we are planning to add a correct implementation.
296306
///
297307
/// See the [`defer`] free function for more details.
298308
pub fn defer(self) -> Result<C::JoinHandle> {
@@ -634,8 +644,8 @@ impl TrampolineArgs for VaList {
634644
// Free functions
635645
////////////////////////////////////////////////////////////////////////////////
636646

637-
/// Creates a new fiber and runs it immediately, returning a [`JoinHandle`] for
638-
/// it.
647+
/// Creates a new fiber and **yields** execution to it immediately, returning a
648+
/// [`JoinHandle`] for the new fiber.
639649
///
640650
/// **NOTE**: The argument `f` is a function that returns `T`. In case when `T =
641651
/// ()` (no return value) one should instead use [`start_proc`].
@@ -655,10 +665,10 @@ where
655665
Builder::new().func(f).start().unwrap()
656666
}
657667

658-
/// Creates a new unit fiber and runs it immediately, returning a
659-
/// [`UnitJoinHandle`] for it.
668+
/// Creates a new proc fiber and **yields** execution to it immediately,
669+
/// returning a [`UnitJoinHandle`] for the new fiber.
660670
///
661-
/// The *unit fiber* is a special case of a fiber whose function does not return
671+
/// The *proc fiber* is a special case of a fiber whose function does not return
662672
/// a value. In fact `UnitJoinHandle` is identical to `JoinHanble<()>` is all
663673
/// aspects instead that it is implemented more efficiently and the former
664674
/// should always be used instead of the latter.
@@ -671,26 +681,40 @@ where
671681
Builder::new().proc(f).start().unwrap()
672682
}
673683

674-
/// Creates and schedules a new deferred fiber, returning a [`JoinHandle`] for
675-
/// it.
684+
#[cfg(any(feature = "defer", doc))]
685+
/// Creates a new fiber and schedules it for exeution, returning a
686+
/// [`JoinHandle`] for it.
687+
///
688+
/// **NOTE:** In the current implementation the current fiber performs a
689+
/// **yield** to start the newly created fiber and then the new fiber
690+
/// performs another **yield**. This means that the deferred fiber is **not
691+
/// applicable for transactions** (which do not allow any context switches).
692+
/// In the future we are planning to add a correct implementation.
676693
///
677694
/// **NOTE**: The argument `f` is a function that returns `T`. In case when `T =
678695
/// ()` (no return value) one should instead use [`defer_proc`].
679696
///
680-
/// The **deferred fiber** is a fiber which starts in a detached mode. It can be
681-
/// joined by calling the [`JoinHandle::join`] method.
697+
/// The new fiber can be joined by calling [`JoinHandle::join`] method on it's
698+
/// join handle.
682699
pub fn defer<F, T>(f: F) -> JoinHandle<T>
683700
where
684701
F: FnOnce() -> T,
685702
{
686703
Builder::new().func(f).defer().unwrap()
687704
}
688705

689-
/// Creates and schedules a new deferred unit fiber, returning a
706+
#[cfg(any(feature = "defer", doc))]
707+
/// Creates a new proc fiber and schedules it for exeution, returning a
690708
/// [`UnitJoinHandle`] for it.
691709
///
692-
/// The **deferred unit fiber** is a fiber which starts in a detached mode. It
693-
/// can be joined by calling the [`UnitJoinHandle::join`] method.
710+
/// **NOTE:** In the current implementation the current fiber performs a
711+
/// **yield** to start the newly created fiber and then the new fiber performs
712+
/// another **yield**. This means that the deferred fiber is **not applicable
713+
/// for transactions** (which do not allow any context switches). In the future
714+
/// we are planning to add a correct implementation.
715+
///
716+
/// The new fiber can be joined by calling [`UnitJoinHandle::join`] method on
717+
/// it's join handle.
694718
///
695719
/// This is an optimized version [`defer`]`<F, ()>`.
696720
pub fn defer_proc<F>(f: F) -> UnitJoinHandle

tarantool/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! - [Fibers: fiber attributes, conditional variables, latches](fiber)
66
//! - [CoIO](coio)
77
//! - [Transactions](transaction)
8-
//! - Schema management
8+
//! - [Schema management](schema)
99
//! - [Protocol implementation](net_box) (`net.box`): CRUD, stored procedure call, triggers
1010
//! - [Tuple utils](mod@tuple)
1111
//! - [Logging](log) (see <https://docs.rs/log/>)

tarantool/src/schema/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "schema")]
1+
#![cfg(any(feature = "schema", doc))]
22

33
pub mod index;
44
pub mod sequence;

0 commit comments

Comments
 (0)