Ticker
struct Ticker
Methods
[src]
pub fn new(period: Duration, start_at: Instant? = nil): Ticker {
let ch = Ticker.init(period, start_at:);
return Ticker { ch };
}
[src]
pub fn new(period: Duration, start_at: Instant? = nil): Ticker {
let ch = Ticker.init(period, start_at:);
return Ticker { ch };
}
[src]
fn init(period: Duration, start_at: Instant? = nil): channel<Instant> {
let ch = channel::<Instant>();
let delay: Duration? = nil;
if (let start_at = start_at) {
delay = start_at - Instant.now();
}
spawn {
do {
if (let delay = delay) {
sleep(delay);
}
loop {
try ch.send(Instant.now());
sleep(period);
}
}
}
return ch;
}
[src]
fn init(period: Duration, start_at: Instant? = nil): channel<Instant> {
let ch = channel::<Instant>();
let delay: Duration? = nil;
if (let start_at = start_at) {
delay = start_at - Instant.now();
}
spawn {
do {
if (let delay = delay) {
sleep(delay);
}
loop {
try ch.send(Instant.now());
sleep(period);
}
}
}
return ch;
}
[src]
pub fn channel(self): channel<Instant> {
return self.ch;
}
[src]
pub fn channel(self): channel<Instant> {
return self.ch;
}
[src]
pub fn reset(self, period: Duration, start_at: Instant? = nil) {
self.ch.close();
self.ch = Ticker.init(period, start_at:);
}
[src]
pub fn reset(self, period: Duration, start_at: Instant? = nil) {
self.ch.close();
self.ch = Ticker.init(period, start_at:);
}
stop
pub fn stop(self)
[src]
pub fn stop(self) {
self.ch.close();
}
stop
pub fn stop(self)
[src]
pub fn stop(self) {
self.ch.close();
}