Skip to main content

EventTail

Struct EventTail 

Source
pub struct EventTail<T> { /* private fields */ }
Expand description

A shared, wakeable, replayable source of stream events.

What a session publishes into and what a response body reads from. It is Send + Sync and holds no borrow of anything, which is the property that lets a body stream outlive the request task that built it — see the module docs on why the stream must not be the thing holding the engine.

Cloning is cheap and shares: every clone reads and writes the same ring, so a router can keep one in its state and hand a reference to each response.

§Example

use core::num::NonZeroUsize;
use serde_json::{Value, json};
use protocol_droid::adapters::primary::transport::http::EventTail;

let capacity = NonZeroUsize::new(4).ok_or("capacity")?;
let tail = EventTail::<Value>::new(capacity);
for index in 0..3 {
    tail.push(json!({ "index": index }));
}
// A client that has seen all three is current and gets no frames.
assert!(tail.plan(Some("3")).resume().pending().is_empty());

Implementations§

Source§

impl<T> EventTail<T>

Source

pub fn new(capacity: NonZeroUsize) -> Self

A tail over a ring retaining capacity events.

RECOMMENDED_CAPACITY is the right value for a caller that has not measured its payloads; pass a real count for one that has.

Source

pub fn len(&self) -> usize

How many events are currently retained.

For a log line or a test assertion. Taking the ring lock is why this is not on any per-frame path.

Source

pub fn is_empty(&self) -> bool

Whether nothing is retained.

Source

pub fn last(&self) -> EventId

The newest event id ever issued, or the watermark if nothing has been.

Source§

impl<T> EventTail<T>
where T: FramePayload,

Source

pub fn push(&self, payload: T) -> EventId

Publishes an event and wakes every stream parked on this tail.

The returned id is the value a client quotes to resume after this event, so a publisher that discards it has made the event unresumable: the next reconnect is told about a gap the client never knew it had.

Source

pub fn plan(&self, header: Option<&str>) -> Planned<T>

Decides what a client that sent header gets, atomically with the watermark it was decided against.

The pairing with the cursor is the point. Resume names the frames to write; the stream needs to know where to continue from. Reading those from two separate lock acquisitions would open the window the module docs describe, so Planned carries both and there is no way to obtain one without the other.

header is the raw Last-Event-ID value, or None for a client that has never seen this stream. A header that is present but unreadable is a refusal, decided before the ring is consulted.

Source§

impl<T> EventTail<T>
where T: FramePayload + Send + 'static,

The response-building half of EventTail, separated by its bound.

The bound is T: Send + 'static because the body it produces has to be sent between threads and outlive the call; push and plan do not carry it, so a caller that only publishes or only inspects never has to satisfy it.

Source

pub fn respond( &self, header: Option<&str>, keep_alive: Duration, ) -> Result<Response, StreamError>

Plans and answers in one call, for a router with nothing to do in between.

§Errors

StreamError::Response if the response headers cannot be assembled.

Trait Implementations§

Source§

impl<T> Clone for EventTail<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for EventTail<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for EventTail<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl EventSource for EventTail<Value>

A tail is its own event source, which is the shape T14’s server uses: one session, one tail. A server keeping more state per session holds the tail as a field and implements this for the session itself.

Source§

fn tail(&self) -> &EventTail<Value>

The tail this session’s server-initiated messages are published on.

Auto Trait Implementations§

§

impl<T> Freeze for EventTail<T>
where Arc<Shared<T>>: Freeze,

§

impl<T> RefUnwindSafe for EventTail<T>
where Arc<Shared<T>>: RefUnwindSafe,

§

impl<T> Send for EventTail<T>
where Arc<Shared<T>>: Send,

§

impl<T> Sync for EventTail<T>
where Arc<Shared<T>>: Sync,

§

impl<T> Unpin for EventTail<T>
where Arc<Shared<T>>: Unpin,

§

impl<T> UnsafeUnpin for EventTail<T>
where Arc<Shared<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for EventTail<T>
where Arc<Shared<T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more