1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//! Backend lifecycle hooks.
//!
//! This module provides wrappers for running asynchronous callbacks at
//! different points in a backend's lifecycle.
//!
//! Hooks are executed at most once and receive a mutable reference to the
//! wrapped backend, allowing them to perform initialization or cleanup work.
//!
//! The hooks are executed in the following order:
//!
//! ```text
//! before_start
//! ↓
//! first poll_ready
//! ↓
//! after_start
//! ↓
//! ... backend operation ...
//! ↓
//! poll_close
//! ↓
//! after_stop
//! ```
//!
//! # Hooks
//!
//! * [`BeforeStart`] runs once before the backend's first `poll_ready` call.
//! * [`AfterStart`] runs once after the backend's first successful `poll_ready`.
//! * [`BeforeStop`] runs once before the backend's `poll_close` call.
//! * [`AfterStop`] runs once after the backend has stopped and cleaned up.
//!
//! The [`BackendExt`] trait provides convenience methods for attaching these
//! hooks to a backend.
//!
//! # Examples
//!
//! A backend can be configured with lifecycle hooks using the extension
//! methods provided by [`BackendExt`]:
//!
//! ```ignore
//! let backend = backend
//! .before_start(|backend| async {
//! // Initialize the backend.
//! Ok(())
//! })
//! .after_start(|backend| async {
//! // Backend is ready.
//! Ok(())
//! })
//! .before_stop(|backend| async {
//! // Prepare for shutdown.
//! Ok(())
//! })
//! .after_stop(|backend| async {
//! // Perform final cleanup.
//! Ok(())
//! });
//! ```
//!
//! Errors returned by a hook are propagated as backend errors and can prevent
//! the corresponding lifecycle transition from completing.
//!
//! [`BackendExt`]: super::BackendExt
use ;
pub use AfterStart;
pub use AfterStop;
pub use BeforeStart;
pub use BeforeStop;
use crateBoxSyncFuture;
type HookFuture<E> = ;
/// One-shot lifecycle hook state, shared by all `*_hook` wrappers below.
type FnHandler<B, Err> =
;