pub struct OrderedTimerDeque<DQI: OrderedTimerDequeIntrf> { /* private fields */ }
Expand description
A VecDeque based queue which is sorted (in ascending order) by the timeout
which is absolute
time.
The queue automatically manages the timer
i.e setting, unsetting.
Also for each type of the deque, a event procesing function is providided.
There are two types of queue:
-
OrderdTimerDequeOnce - after timeout the element is removed from the queue.
-
OrderdTimerDequePeriodic - after timeout the element timeout is extended until the item is not removed from the queue manually.
§Generics
DQI
- a deque type. There are three types are available:-
- crate::TimerDequeueTicketIssuer issues a ticket for the instance for which the timer was set.
ⓘorlet mut time_list = OrderedTimerDeque ::<TimerDequeueTicketIssuer<OrderdTimerDequeOnce>> ::new("test_label".into(), 4, false).unwrap();
ⓘlet mut time_list = OrderedTimerDeque ::<TimerDequeueTicketIssuer<OrderdTimerDequePeriodic>> ::new("test_label".into(), 4, false).unwrap();
-
- crate::TimerDequeueConsumer consumes the instance for which the timer is set.
ⓘorlet mut time_list = OrderedTimerDeque ::<TimerDequeueConsumer<TestItem, OrderdTimerDequeOnce>> ::new("test_label".into(), 4, false).unwrap();
ⓘlet mut time_list = OrderedTimerDeque ::<TimerDequeueConsumer<TestItem, OrderdTimerDequePeriodic>> ::new("test_label".into(), 4, false).unwrap();
-
- crate::TimerDequeueSignalTicket sends a signal to destination.
ⓘorlet mut time_list = OrderedTimerDeque ::<TimerDequeueSignalTicket<TestSigStruct, OrderdTimerDequeOnce>> ::new("test_label".into(), 4, false).unwrap();
ⓘlet mut time_list = OrderedTimerDeque ::<TimerDequeueSignalTicket<TestSigStruct, OrderdTimerDequePeriodic>> ::new("test_label".into(), 4, false).unwrap();
-
Implementations§
Source§impl<R> OrderedTimerDeque<TimerDequeueConsumer<R, OrderdTimerDequeOnce>>
impl<R> OrderedTimerDeque<TimerDequeueConsumer<R, OrderdTimerDequeOnce>>
Sourcepub fn add_to_timer(
&mut self,
entity: R,
abs_time: AbsoluteTime,
) -> TimerResult<NoTicket>
pub fn add_to_timer( &mut self, entity: R, abs_time: AbsoluteTime, ) -> TimerResult<NoTicket>
Adds the new absolute timeout to the timer dequeue instance.
The entity
is an item which should be stored in the dequeue.
§Arguemnts
entity
- R
generic which is an item to store in the dequeu.
abs_time
- a AbsoluteTime absolute time in future when the timeout
should happen.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the common::NoTicket ticket which is dummy value.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
timeout_items: &mut Vec<R>,
) -> TimerResult<()>
pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<R>, ) -> TimerResult<()>
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of an enitities for which timeout have happened.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<R> OrderedTimerDeque<TimerDequeueConsumer<R, OrderdTimerDequePeriodic>>
impl<R> OrderedTimerDeque<TimerDequeueConsumer<R, OrderdTimerDequePeriodic>>
Sourcepub fn add_to_timer(
&mut self,
entity: R,
rel_time: RelativeTime,
) -> TimerResult<NoTicket>
pub fn add_to_timer( &mut self, entity: R, rel_time: RelativeTime, ) -> TimerResult<NoTicket>
Adds the new entry to the timout queue which after alarm extends the timeout and sets the instance in the queue again.
The entity
is an item which should be stored in the dequeue and
impl Clone.
§Arguemnts
entity
- R
generic which is an item to store in the dequeu.
rel_time
- a RelativeTime which will be used to extend the further
timeouts.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the common::NoTicket ticket which is dummy value.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
timeout_items: &mut Vec<R>,
) -> TimerResult<()>
pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<R>, ) -> TimerResult<()>
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of an enitities for which timeout have happened.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<R, MODE> OrderedTimerDeque<TimerDequeueConsumer<R, MODE>>
impl<R, MODE> OrderedTimerDeque<TimerDequeueConsumer<R, MODE>>
Sourcepub fn remove_from_sched_queue(&mut self, entity: &R) -> TimerResult<Option<R>>
pub fn remove_from_sched_queue(&mut self, entity: &R) -> TimerResult<Option<R>>
Removes the instance from the queue by the reference to entity.
§Arguments
entity
- R
reference to added item which will be used to identify the
item ont he record.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the inner type Option where
- Option::Some is returned with the consumed
entity
. - Option::None is returned when item was not found.
- Option::Some is returned with the consumed
-
Result::Err with error description.
Source§impl OrderedTimerDeque<TimerDequeueTicketIssuer<OrderdTimerDequeOnce>>
impl OrderedTimerDeque<TimerDequeueTicketIssuer<OrderdTimerDequeOnce>>
Sourcepub fn add_to_timer(
&mut self,
abs_time: AbsoluteTime,
) -> TimerResult<TimerDequeueTicket>
pub fn add_to_timer( &mut self, abs_time: AbsoluteTime, ) -> TimerResult<TimerDequeueTicket>
Adds the new entry to the timeout qeueu which after alarm
removes the entry from the queue. A ticket
will be
issued which can be used to either deactivate the record
by droppping it or to remove it manually.
§Arguemnts
abs_time
- a AbsoluteTime absolute time in future when the timeout
should happen.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the TimerDequeueTicket ticket.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
timeout_items: &mut Vec<TimerDequeueId>,
) -> TimerResult<()>
pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<TimerDequeueId>, ) -> TimerResult<()>
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of an enitities for which timeout have happened.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl OrderedTimerDeque<TimerDequeueTicketIssuer<OrderdTimerDequePeriodic>>
impl OrderedTimerDeque<TimerDequeueTicketIssuer<OrderdTimerDequePeriodic>>
Sourcepub fn add_to_timer(
&mut self,
rel_time: RelativeTime,
) -> TimerResult<TimerDequeueTicket>
pub fn add_to_timer( &mut self, rel_time: RelativeTime, ) -> TimerResult<TimerDequeueTicket>
Adds the new entry to the timeout queue which after alarm
extends the timeout and sets the instance in the queue again.
A ticket
will be issued which can be used to either deactivate
the record by droppping it or to remove it manually.
§Arguemnts
rel_time
- a RelativeTime which will be used to extend the further
timeouts. .
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the TimerDequeueTicket ticket.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
timeout_items: &mut Vec<TimerDequeueId>,
) -> TimerResult<()>
pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, timeout_items: &mut Vec<TimerDequeueId>, ) -> TimerResult<()>
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of an enitities for which timeout have happened.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<MODE: OrderedTimerDequeMode> OrderedTimerDeque<TimerDequeueTicketIssuer<MODE>>
impl<MODE: OrderedTimerDequeMode> OrderedTimerDeque<TimerDequeueTicketIssuer<MODE>>
Sourcepub fn remove_from_sched_queue(
&mut self,
ticket: TimerDequeueTicket,
) -> TimerResult<()>
pub fn remove_from_sched_queue( &mut self, ticket: TimerDequeueTicket, ) -> TimerResult<()>
Removes the instance from the queue by the issued ticket
.
§Arguments
ticket
- TimerDequeueTicket an issued ticket.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, OrderdTimerDequeOnce>>where
SIG: TimerDequeueSignal,
impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, OrderdTimerDequeOnce>>where
SIG: TimerDequeueSignal,
Sourcepub fn add_to_timer(
&mut self,
sig_hnd: SIG,
abs_time: AbsoluteTime,
) -> TimerResult<NoTicket>
pub fn add_to_timer( &mut self, sig_hnd: SIG, abs_time: AbsoluteTime, ) -> TimerResult<NoTicket>
Adds the new absolute
(relative
) timeout to the timer dequeue.
§Arguemnts
sig_hnd
- a SIG
generic instance which would identify the instance and
provide identification.
abs_time
- a AbsoluteTime absolute time in future when the timeout
should happen.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the [TimerDequeueTicket] ticket.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
) -> TimerResult<()>
pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of tickets which were not dropped and timeout.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Sourcepub async fn async_timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
) -> TimerResult<()>
pub async fn async_timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>
An async version of the event handler.
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of tickets which were not dropped and timeout.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, OrderdTimerDequePeriodic>>where
SIG: TimerDequeueSignal,
impl<SIG> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, OrderdTimerDequePeriodic>>where
SIG: TimerDequeueSignal,
Sourcepub fn add_to_timer(
&mut self,
sig_hnd: SIG,
rel_time: RelativeTime,
) -> TimerResult<NoTicket>
pub fn add_to_timer( &mut self, sig_hnd: SIG, rel_time: RelativeTime, ) -> TimerResult<NoTicket>
Adds the new periodic
timeout to the timer dequeue.
§Arguemnts
sig_hnd
- a SIG
generic instance which would identify the instance and
provide identification.
rel_time
- a RelativeTime which will be used to extend the further
timeouts.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok with the [TimerDequeueTicket] ticket.
-
Result::Err with error description.
Sourcepub fn timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
) -> TimerResult<()>
pub fn timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of tickets which were not dropped and timeout.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Sourcepub async fn async_timeout_event_handler(
&mut self,
res: TimerReadRes<u64>,
) -> TimerResult<()>
pub async fn async_timeout_event_handler( &mut self, res: TimerReadRes<u64>, ) -> TimerResult<()>
An async version of the event handler.
Handles the event which was read
from the timer. The functions Self::wait_for_event
or Self::poll can be used to obtain the event.
§Arguments
res
- TimerReadRes an event from the timer to handle.
timeout_items
- a vector of tickets which were not dropped and timeout.
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<SIG, MODE> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, MODE>>where
SIG: TimerDequeueSignal,
MODE: OrderedTimerDequeMode,
impl<SIG, MODE> OrderedTimerDeque<TimerDequeueSignalTicket<SIG, MODE>>where
SIG: TimerDequeueSignal,
MODE: OrderedTimerDequeMode,
Sourcepub fn remove_from_sched_queue(
&mut self,
arg_uniq_id: &SIG::TimerQueueID,
) -> TimerResult<Option<()>>
pub fn remove_from_sched_queue( &mut self, arg_uniq_id: &SIG::TimerQueueID, ) -> TimerResult<Option<()>>
Removes the instance from the queue by the SIG::TimerQueueID
ID.
§Arguments
arg_uniq_id
- a reference to instance’s ID SIG::TimerQueueID
.
§Returns
A Result as alias TimerResult is returned with:
-
Result::Ok witout any innder data.
-
Result::Err with error description.
Source§impl<DQI> OrderedTimerDeque<DQI>where
DQI: OrderedTimerDequeIntrf,
impl<DQI> OrderedTimerDeque<DQI>where
DQI: OrderedTimerDequeIntrf,
Sourcepub fn new(
timer_label: Cow<'static, str>,
deq_len: usize,
cloexec: bool,
) -> TimerResult<OrderedTimerDeque<DQI>>
pub fn new( timer_label: Cow<'static, str>, deq_len: usize, cloexec: bool, ) -> TimerResult<OrderedTimerDeque<DQI>>
Creates new deque instance.
§Argument
timer_label
- a label which helps to identify the timer.
deq_len
- a minimal, pre-allocated deque length.
cloexec
- when set to true
sets the CLOEXEC
flag to FD.
§Returns
A Result as alias TimerResult is returned with
-
Result::Ok with the instance.
-
Result::Err with the error description.
Sourcepub fn wait_for_event(&self) -> TimerResult<TimerReadRes<u64>>
pub fn wait_for_event(&self) -> TimerResult<TimerReadRes<u64>>
Reads the FD to retrive the event type.
This function behaves differently when the timer is set with TimerFlags::TFD_NONBLOCK.
Normally, all timer_* creates nonblocking timer, so this function behaves like when the TimerFlags::TFD_NONBLOCK is set.
When TimerFlags::TFD_NONBLOCK is not set, this function will block reading the FD. In case of ‘EINTR’, the read attempt will be repeated. It will be reapeated in both cases.
When TimerFlags::TFD_NONBLOCK is set, the function will return with some result.
§Return
-
In case of
EAGAIN
, the TimerReadRes::WouldBlock will be returned. -
In case of
ECANCELLD
, the TimerReadRes::WouldBlock will be returned. -
In case of any other error the Result::Err is returned.
When a timer fires an event the Result::Ok is returned with the amount of timer overrun. Normally it is 1.
Sourcepub async fn poll(&self) -> TimerResult<TimerReadRes<u64>>
pub async fn poll(&self) -> TimerResult<TimerReadRes<u64>>
Asynchronious polling. The timer’s FD is set to nonblocking,
so each time it will return pending
and load CPU. If you are using
tokio
or smol
suing corresponding helpers like tokio’s AsyncFd
.
Sourcepub fn timer_queue_len(&self) -> usize
pub fn timer_queue_len(&self) -> usize
Returns the queue length.
Sourcepub fn reschedule_timer(&mut self) -> TimerResult<()>
pub fn reschedule_timer(&mut self) -> TimerResult<()>
Setting the timer
instance to the new values or unsets the timer if
queue
becomes empty.
Sourcepub fn clean_up_timer(&mut self) -> TimerResult<()>
pub fn clean_up_timer(&mut self) -> TimerResult<()>
Unarms timer and clears the queue.
Sourcepub fn stop_timer(&mut self) -> TimerResult<()>
pub fn stop_timer(&mut self) -> TimerResult<()>
Unarms timer only.