pub struct Net { /* private fields */ }Expand description
A node on the Net mesh.
This is the main SDK handle. Every computer, device, and application
is a Net node — there are no clients, no servers, no coordinators.
§Example
use net_sdk::{Net, Backpressure};
let node = Net::builder()
.shards(4)
.backpressure(Backpressure::DropOldest)
.memory()
.build()
.await?;
node.emit(&serde_json::json!({"token": "hello"}))?;
let response = node.poll(net_sdk::PollRequest { limit: 100, ..Default::default() }).await?;
for event in &response.events {
println!("{}", event.raw_str().unwrap_or("<non-utf8>"));
}
node.shutdown().await?;Implementations§
Source§impl Net
impl Net
Sourcepub fn builder() -> NetBuilder
pub fn builder() -> NetBuilder
Create a builder for configuring a new node.
Sourcepub fn emit<T: Serialize>(&self, event: &T) -> Result<Receipt>
pub fn emit<T: Serialize>(&self, event: &T) -> Result<Receipt>
Emit a serializable event.
Serializes T to JSON via serde and ingests it.
Sourcepub fn emit_raw(&self, bytes: impl Into<Bytes>) -> Result<Receipt>
pub fn emit_raw(&self, bytes: impl Into<Bytes>) -> Result<Receipt>
Emit raw bytes (fastest path).
Sourcepub fn emit_batch<T: Serialize>(&self, events: &[T]) -> Result<usize>
pub fn emit_batch<T: Serialize>(&self, events: &[T]) -> Result<usize>
Emit a batch of serializable events. Returns the number ingested.
Sourcepub fn emit_raw_batch(&self, events: Vec<Bytes>) -> usize
pub fn emit_raw_batch(&self, events: Vec<Bytes>) -> usize
Emit a batch of raw byte events. Returns the number ingested.
Sourcepub async fn poll(&self, request: PollRequest) -> Result<PollResponse>
pub async fn poll(&self, request: PollRequest) -> Result<PollResponse>
One-shot poll for events.
Sourcepub fn subscribe(&self, opts: SubscribeOpts) -> EventStream
pub fn subscribe(&self, opts: SubscribeOpts) -> EventStream
Subscribe to a stream of events.
Returns an async Stream that yields events with adaptive backoff.
Sourcepub fn subscribe_typed<T: DeserializeOwned>(
&self,
opts: SubscribeOpts,
) -> TypedEventStream<T>
pub fn subscribe_typed<T: DeserializeOwned>( &self, opts: SubscribeOpts, ) -> TypedEventStream<T>
Subscribe to a typed stream of events.
Each event is automatically deserialized into T.
Sourcepub async fn shutdown(self) -> Result<()>
pub async fn shutdown(self) -> Result<()>
Gracefully shut down the node.
Drains pending events through the adapter and signals all
background tasks to exit. Safe to call even when other
Arc<EventBus> clones exist (e.g. an outstanding
EventStream from subscribe): EventBus::shutdown_via_ref
is idempotent and reference-based, so the shutdown work runs
regardless of strong-ref count, and outstanding clones
observe the bus as shut down on their next operation.