pub struct EventQueue<E: SubscriptionItem = Event> { /* private fields */ }Expand description
A queue of the events of one subscription (EventQueue.create(DXFeedSubscription)): a poll returns them as E, in
their order.
The queue closes when the subscription closes, when close is called and when it is dropped. The
subscription keeps the executor of the queue for its life, also after the queue is closed. The queue can be shared
by threads, but poll it from one thread at a time.
Implementations§
Source§impl<E: SubscriptionItem> EventQueue<E>
impl<E: SubscriptionItem> EventQueue<E>
Sourcepub fn new(subscription: &DXFeedSubscription<E>) -> Result<Self>
pub fn new(subscription: &DXFeedSubscription<E>) -> Result<Self>
Creates a queue of the events of subscription.
Create it before the symbols are added to a subscription attached to a feed. A subscription with an executor or
a queue, or one attached to a feed that has symbols, is Error::Java of java.lang.IllegalStateException;
on a subscription that has symbols, add its event listeners first.
Sourcepub fn wake_up(&self) -> Result<()>
pub fn wake_up(&self) -> Result<()>
Makes the poll in progress, or the next one, return PollResult::NoEvents at once unless it has events;
several wake-ups before a poll wake up one poll.
Sourcepub fn close(&self) -> Result<()>
pub fn close(&self) -> Result<()>
Closes the queue: the poll in progress returns the events it has or PollResult::Closed, and the events that
no poll returned are dropped and counted. It does not wait for the poll in progress; closing a closed queue
does nothing.
Sourcepub fn get_dropped_events(&self) -> Result<i64>
pub fn get_dropped_events(&self) -> Result<i64>
The number of the events of the subscription that were lost, which never decreases: if it grew since the previous poll, events were lost before those that the last poll returned.
Sourcepub unsafe fn set_ready_signal(&self, signal: ReadySignal) -> Result<()>
pub unsafe fn set_ready_signal(&self, signal: ReadySignal) -> Result<()>
Sets, replaces or removes the ready signal of the queue (dxfg_v4_EventQueue_setReadySignal); see
ReadySignal. Needs the cargo feature experimental.
§Safety
The object of the signal must stay open, and be the same object, until another signal replaces it,
ReadySignal::None removes it, close returns on any thread or a poll returns
PollResult::Closed: the SDK writes to it until then. Dropping the queue or closing its subscription does not
count; to stop an event loop, close the queue, and close the object after a poll returns Closed.
Source§impl<E: SubscriptionItem + TryFrom<Event>> EventQueue<E>
impl<E: SubscriptionItem + TryFrom<Event>> EventQueue<E>
Sourcepub fn poll(
&self,
timeout: Option<Duration>,
limit: usize,
) -> Result<PollResult<Vec<E>>>
pub fn poll( &self, timeout: Option<Duration>, limit: usize, ) -> Result<PollResult<Vec<E>>>
Waits for the events of the subscription and returns them; the event listeners of the subscription run in the poll, on this thread.
timeout is how long to wait: zero returns at once, None waits until events arrive, the queue is woken up or
closed. After the first events the poll only completes the retrieval in progress. limit stops the retrieval
after that many events, 0 for no limit; a batch may exceed it. A failure of the SDK drops the events that the
poll took, counted in get_dropped_events, and the next poll goes on with the next
ones; an event that the crate cannot copy fails the poll and drops its batch without counting it.
Inside a listener or a callback of the crate it returns Error::InCallback.