pub struct Hooks { /* private fields */ }Expand description
The hook registry: before / after hooks per event type, plus lifecycle hooks.
Implementations§
Source§impl Hooks
impl Hooks
Sourcepub fn in_tx<E, F>(&mut self, hook: F)
pub fn in_tx<E, F>(&mut self, hook: F)
Register an in_tx hook for events of type E: it runs inside the module’s transaction
(after the module’s own write, before the commit) and may write with the transaction or
refuse (the transaction rolls back, the client gets the error). It uses only tx and may
run more than once (a transaction retried after a deadlock; see the module docs).
use net_backend_server::hooks::{Event, Hooks};
struct SaveWritten { user: i64 }
impl Event for SaveWritten { const NAME: &'static str = "game.save_written"; }
let mut hooks = Hooks::default();
hooks.in_tx::<SaveWritten, _>(|tx, _ctx, event| Box::pin(async move {
let _ = (tx, event.user); // e.g. tx.execute(&update_inventory_statement).await?;
Ok(())
}));Sourcepub fn on_start<F, Fut>(&mut self, hook: F)
pub fn on_start<F, Fut>(&mut self, hook: F)
Register a start hook (runs after every module started; an error aborts the start).
Sourcepub fn on_shutdown<F, Fut>(&mut self, hook: F)
pub fn on_shutdown<F, Fut>(&mut self, hook: F)
Register a shutdown hook (runs after in-flight requests drained, before the database closes).
Sourcepub fn before_count<E: Event>(&self) -> usize
pub fn before_count<E: Event>(&self) -> usize
How many before hooks are registered for E.
Sourcepub fn in_tx_count<E: Event>(&self) -> usize
pub fn in_tx_count<E: Event>(&self) -> usize
How many in_tx hooks are registered for E.
Sourcepub async fn run_in_tx<E: Event>(
&self,
tx: &mut DbTx,
ctx: &HookCtx,
event: &E,
) -> Result<(), AppError>
pub async fn run_in_tx<E: Event>( &self, tx: &mut DbTx, ctx: &HookCtx, event: &E, ) -> Result<(), AppError>
Run the in_tx hooks of E in order inside tx. The first error stops the chain and is
returned (roll the transaction back); a timeout is 503 hook_timeout, a panic 500
internal.
Sourcepub fn after_count<E: Event>(&self) -> usize
pub fn after_count<E: Event>(&self) -> usize
How many after hooks are registered for E.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Hooks
impl !UnwindSafe for Hooks
impl Freeze for Hooks
impl Send for Hooks
impl Sync for Hooks
impl Unpin for Hooks
impl UnsafeUnpin for Hooks
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more