Skip to main content

notedthat_write/
sinks.rs

1//! Where a committed write is announced: the indexing queue and, when one is
2//! configured, the object change event log.
3//!
4//! Bundled so every write path takes one argument and every surface names its
5//! [`EventSource`] once, where it builds the bundle, rather than at each call.
6
7use notedthat_core::{EventPublisher, EventSource};
8use notedthat_indexer::IndexEvent;
9use tokio::sync::mpsc::Sender;
10
11/// The two places a durable write is reported to, and on whose behalf.
12#[derive(Clone, Copy)]
13pub struct WriteSinks<'a> {
14    /// The in-process indexing queue (D38).
15    pub indexer_tx: &'a Sender<IndexEvent>,
16    /// The event log, when `NOTEDTHAT_EVENTS_BACKEND` selects one.
17    pub events: Option<&'a dyn EventPublisher>,
18    /// The surface making the write, stamped on every event it publishes.
19    pub source: EventSource,
20}
21
22impl<'a> WriteSinks<'a> {
23    /// Both sinks.
24    #[must_use]
25    pub fn new(
26        indexer_tx: &'a Sender<IndexEvent>,
27        events: Option<&'a dyn EventPublisher>,
28        source: EventSource,
29    ) -> Self {
30        Self {
31            indexer_tx,
32            events,
33            source,
34        }
35    }
36
37    /// The indexing queue alone, as every deployment without an events backend
38    /// runs, attributed to the HTTP API.
39    #[must_use]
40    pub fn indexer_only(indexer_tx: &'a Sender<IndexEvent>) -> Self {
41        Self::new(indexer_tx, None, EventSource::Http)
42    }
43}