Last active
July 11, 2021 12:17
-
-
Save qmzik/52b5d6c1ce221ef5b0e87d30a89f92d7 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* A simple object with a `next` and `complete` callback on it. | |
*/ | |
interface Observer<T> { | |
next: (value: T) => void; | |
complete: () => void; | |
} | |
/** | |
* A function that takes a simple object with callbacks | |
* and does something them. | |
*/ | |
const source = (subscriber: Observer<number>) => { | |
subscriber.next(1); | |
subscriber.next(2); | |
subscriber.next(3); | |
subscriber.complete(); | |
}; | |
// Usage | |
console.log('start'); | |
source({ | |
next: console.log, | |
complete: () => console.log('done'), | |
}); | |
console.log('stop'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment