Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/async_channels/src/time.ts>timeout

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

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>