Created
August 10, 2025 21:01
-
-
Save DeadWisdom/17ccf47d3beee85a3ab5467709c51811 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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