Skip to main content
Module

x/async_channels/mod.ts>time.after

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

after waits for the duration to elapse and then sends the current time on the returned channel. It is equivalent to (new Timer(d)).c. If efficiency is a concern, use new Timer() instead and call Timer.stop if the timer is no longer needed.

Examples

Example 1

import { Channel, select, time } from "./mod.ts"

async function foo<T>(ch: Channel<T>): Promise<T> {
  const res = await select([
    ch,
    time.after(10 * time.Duration.Second),
  ]);
  if (res[1] !== ch) throw new Error(`foo timed out at: ${res[0]}`);
  return res[0] as T;
}

type

(duration: number) => Receiver<Date>