Skip to content

Instantly share code, notes, and snippets.

@mattpodwysocki
Created March 29, 2020 01:56
Show Gist options
  • Save mattpodwysocki/7333d774dab3a3278805b4b3b2ed7d5d to your computer and use it in GitHub Desktop.
Save mattpodwysocki/7333d774dab3a3278805b4b3b2ed7d5d to your computer and use it in GitHub Desktop.
import { AsyncIterableX } from './asynciterablex';
import { throwIfAborted, AbortError } from '../aborterror';
export class NeverAsyncIterable extends AsyncIterableX<never> {
constructor() {
super();
}
async *[Symbol.asyncIterator](signal?: AbortSignal) {
throwIfAborted(signal);
await new Promise<never>((_, reject) => {
if (signal) {
signal.addEventListener('abort', () => reject(new AbortError()), { once: true });
}
});
}
}
export function never(): AsyncIterableX<never> {
return new NeverAsyncIterable();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment