pub struct MtgaEventStream { /* private fields */ }Expand description
Handle for a running MTG Arena event stream.
Created by MtgaEventStream::start, which opens the log file, wires
together the tailer, router, and event bus, and spawns a background task
on the caller’s Tokio runtime. The returned Subscriber receives
typed GameEvent values as they are parsed.
Call shutdown to stop the background task and clean
up resources. Dropping the MtgaEventStream without calling shutdown
is safe – the background task will stop when the EventBus is dropped
and the entry channel closes.
§Runtime requirement
MtgaEventStream does not create its own Tokio runtime. It must be
used from within an active Tokio context (e.g., inside #[tokio::main]
or #[tokio::test]).
Implementations§
Source§impl MtgaEventStream
impl MtgaEventStream
Sourcepub async fn start(log_path: &Path) -> Result<(Self, Subscriber), StreamError>
pub async fn start(log_path: &Path) -> Result<(Self, Subscriber), StreamError>
Starts streaming events from the given log file path.
Opens the log file for tailing from the beginning (catch-up mode), creates an event bus and router, and spawns a background task that:
- Polls the file tailer for new log entries
- Routes each entry through the parser dispatch chain
- Sends recognized events to the event bus
Returns a tuple of (MtgaEventStream, Subscriber). The
Subscriber receives cloned GameEvent values. Call
shutdown on the MtgaEventStream to stop
the background task.
§Errors
Returns StreamError::Tailer if the log file cannot be opened.
Sourcepub async fn start_once(
log_path: &Path,
) -> Result<(Self, Subscriber), StreamError>
pub async fn start_once( log_path: &Path, ) -> Result<(Self, Subscriber), StreamError>
Starts a one-shot event stream that reads an entire log file and exits.
Opens the file via FileTailer::open_from_start, reads all
entries, routes them through the parser dispatch chain, and sends
recognized events to the event bus. The pipeline stops
automatically at EOF rather than polling indefinitely.
This is useful for batch processing complete log files (smoke tests,
replay analysis, importing Player-prev.log).
Returns a tuple of (MtgaEventStream, Subscriber). The Subscriber
will receive None once all events have been delivered and the
pipeline finishes. Calling shutdown on a
one-shot stream is a no-op – the pipeline exits at EOF on its own.
§Errors
Returns StreamError::Tailer if the log file cannot be opened.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Signals the background pipeline to stop.
The tailer flushes any remaining buffered entries before exiting.
The Subscriber will receive None once all buffered events
have been delivered and the event bus is dropped.