Last active
January 16, 2017 22:50
-
-
Save mlhaufe/07d774edcdec10da7d9f61e1d6b8b670 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
interface Publisher<T> { | |
subscribe(s: Subscriber<T>): void | |
} | |
interface Subscriber<T> { | |
onNext(value: T): void | |
onError(e: Error): void | |
onDone(): void | |
onSubscribe(s: Subscription): void | |
} | |
interface Subscription { | |
take(n: number): void // take(0) means pause if Observable? | |
cancel(): void | |
} | |
// Pull-based (Interactive) | |
interface Iterable<T> extends Publisher<T> { | |
//take(0) => ? | |
//take(n) => iterate? | |
//take(infinity) => take entire list? (implies n is exclusive) | |
} | |
//Push-based (Reactive) | |
// compare with interface Stream<T> | |
interface Observable<T> extends Publisher<T> { | |
//take(0) => pause? | |
//take(n) => generate? | |
//take(infinity) => resume? | |
} | |
//////////////////// | |
interface Stream<T> { | |
listen( | |
onData: (v: T => void), | |
onError: (e: Error => void), | |
onDone: () => void | |
): StreamSubscription | |
} | |
interface StreamSubscription { | |
cancel(): Future //??? | |
pause(): void | |
resume(): void | |
} | |
//f(a: A): (B => void) => void | |
//f(a: A): Future<T> | |
// Futures are CPS with currying | |
// 2 continuations: success and cancel... | |
interface Future<T> {} | |
//TODO: Cancellation <https://youtu.be/pOl4E8x3fmw?t=2851> | |
interface AyncIterable<T> { | |
iterator(): AsyncIterator<T> | |
} | |
interface AsyncIterator<T> { | |
moveNext: Future<boolean> | |
current: T | |
} | |
interface AsyncSubscription { | |
cancel(): Future<void> | |
isCancelled: boolean | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment