Skip to content

Instantly share code, notes, and snippets.

@mlhaufe
Last active January 16, 2017 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlhaufe/07d774edcdec10da7d9f61e1d6b8b670 to your computer and use it in GitHub Desktop.
Save mlhaufe/07d774edcdec10da7d9f61e1d6b8b670 to your computer and use it in GitHub Desktop.
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