import { Timer } from "https://deno.land/x/async_channels@v1.0.0-alpha54/time.ts";
reset
changes the timer to expire after duration
.
It returns true
if the timer had been active, false
if the timer had
expired or been stopped.
reset should be invoked only on stopped or expired timers with drained channels.
If a program has already received a value from t.c
, the timer is known
to have expired and the channel drained, so t.reset()
can be used directly.
If a program has not yet received a value from t.c
, however,
the timer must be stopped and—if stop reports that the timer expired
before being stopped—the channel explicitly drained:
if (!t.stop()) {
await t.c.receive()
}
t.reset(d)
This should not be done concurrent to other receives from the Timer's channel.
Note that it is not possible to use reset's return value correctly, as there is a race condition between draining the channel and the new timer expiring. reset should always be invoked on stopped or expired channels, as described above. The return value exists to preserve compatibility with existing programs.