Skip to main content
Module

x/async_channels/mod.ts>time.Timer#stop

Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
Latest
method time.Timer.prototype.stop
import { time } from "https://deno.land/x/async_channels@v1.0.0-rc8/mod.ts";
const { Timer } = time;

stop prevents the Timer from firing. It returns true if the call stops the timer, false if the timer has already expired or been stopped. stop does not close the channel, to prevent a read from the channel succeeding incorrectly.

To ensure the channel is empty after a call to stop, check the return value and drain the channel. For example, assuming the program has not received from t.C already:

if (!t.stop()) {
  await t.c.get()
}

This cannot be done concurrent to other receives from the Timer's channel or other calls to the Timer's stop method.

For a timer created with AfterFunc(d, f), if t.stop returns false, then the timer has already expired and the function f has been started in its own goroutine; stop does not wait for f to complete before returning. If the caller needs to know whether f is completed, it must coordinate with f explicitly.

Returns

boolean