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

x/async_channels/channel.ts>Channel#with

Inspired by Go & Clojure Channels, async_channels provides channels as an asynchronous communication method between asynchronous functions.
Go to Latest
method Channel.prototype.with
import { Channel } from "https://deno.land/x/async_channels@v1.0.0-alpha54/channel.ts";

Applies fn on this and returns the result.

Examples

Example 1

import { Channel } from "./channel.ts";
import { map } from "./pipe.ts";
const srcCh = new Channel<number>(1);
const resCh = srcCh.with(map(n => n * 2));
await srcCh.send(5);
srcCh.close();
console.assert(await resCh.receive() === [10, true]);

Type Parameters

TOut
TThis extends Channel<T>

Parameters

this: TThis
fn: (t: TThis) => TOut