Skip to main content
Module

x/async_channels/mod.ts>tagged.select

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

A tagged-template version of select.

Format:

import {Channel} from "../channel.ts";
import {select} from "./select.ts";
const ch1 = new Channel();
const ch2 = new Channel();
const res = await select`
  case ${ch1}: ${(val) => "Will be called if ch1 was sent val"}
  case ${[ch2, "val"]}: ${() => "Will be called if ch2 accepted 'val'"}
  default: ${() => "Will be called if no other channel is ready for get / send"}
`
console.log(res)

Parameters

strings: TemplateStringsArray
...args: (SelectOperation<unknown> | SelectHandler<unknown, unknown>)[]