/// Result of a receive operation. pub(crate) type TickToken = Option<Instant>;
/// Channel that delivers messages periodically. pub(crate) struct Channel { /// The instant at which the next message will be delivered.
delivery_time: AtomicCell<Instant>,
/// The time interval in which messages get delivered.
duration: Duration,
}
/// Attempts to receive a message without blocking. #[inline] pub(crate) fn try_recv(&self) -> Result<Instant, TryRecvError> { loop { let now = Instant::now(); let delivery_time = self.delivery_time.load();
if now < delivery_time { return Err(TryRecvError::Empty);
}
/// Receives a message from the channel. #[inline] pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<Instant, RecvTimeoutError> { loop { let delivery_time = self.delivery_time.load(); let now = Instant::now();
iflet Some(d) = deadline { if d < delivery_time { if now < d {
thread::sleep(d - now);
} return Err(RecvTimeoutError::Timeout);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.