Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Machina

import { Machina } from "https://gitlab.com/soapbox-pub/nostr-machina/-/raw/main/mod.ts";

Infinite async generator. Iterates messages pushed to it until closed. Only one consumer is expected to use a Machina instance at a time.

@example
// Create the Machina instance
const machina = new Machina<string>();

// Async generator loop
async function getMessages() {
  for await (const msg of machina.stream()) {
    console.log(msg);
  }
}

// Start the generator
getMessages();

// Push messages to it
machina.push('hello!');
machina.push('whats up?');
machina.push('greetings');

// Stop the generator
machina.close();
class Machina<T> {
close(): void;
push(data: T): void;
async *stream(): AsyncGenerator<T>;
}

§Type Parameters

§Methods

§
close(): void
[src]

Closes the Machina instance, ending the stream. Calling stream() again causes it to be re-opened.

§
push(data: T): void
[src]

Push a message into the Machina instance, making it available to the consumer of stream().

§
stream(): AsyncGenerator<T>
[src]

Get messages as an AsyncGenerator.