Skip to content

Instantly share code, notes, and snippets.

@DeadWisdom
Created August 10, 2025 21:01
Show Gist options
  • Select an option

  • Save DeadWisdom/17ccf47d3beee85a3ab5467709c51811 to your computer and use it in GitHub Desktop.

Select an option

Save DeadWisdom/17ccf47d3beee85a3ab5467709c51811 to your computer and use it in GitHub Desktop.
class Stream<T> {
items: T[] = [];
_unsubscribe?: () => void;
next(fn: (data: any[]) => void): Stream<T> { return this; }
error(fn: (error: any) => void): Stream<T> { return this; }
complete(fn: () => void) { return this; }
unsubscribe() {
this._unsubscribe?.();
}
/*
* Returns all items once it has produced any
*/
async load() {
return this.items;
}
/*
* Returns the first item produced by the stream once it has produced any
*/
async loadOne() {
return this.items[0]!;
}
/*
* Returns the next array of items produced by the stream
*/
async tail() {
return this.items;
}
async tailOne() {
return this.items[0]!;
}
}
function thing() {
let stream = new Stream().next((data) => {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment