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>;