Skip to main content
Module

x/async_channels/mod.ts>time.timeout

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

timeout creates a channel that will close after duration milliseconds.

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.timeout(10 * time.Duration.Second),
  ]);
  if (res[1] !== ch) throw new Error("foo timed out");
  return res[0] as T;
}

type

(duration: number, options?: ChannelOptions) => Receiver<void>