Skip to content

Instantly share code, notes, and snippets.

@qmzik
Last active July 11, 2021 12:17
Show Gist options
  • Save qmzik/52b5d6c1ce221ef5b0e87d30a89f92d7 to your computer and use it in GitHub Desktop.
Save qmzik/52b5d6c1ce221ef5b0e87d30a89f92d7 to your computer and use it in GitHub Desktop.
/**
* 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