Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wschella/asynciteratorasync
An AsyncIterator extensions that allows for async closures in utility methods
https://github.com/wschella/asynciteratorasync
Last synced: 6 days ago
JSON representation
An AsyncIterator extensions that allows for async closures in utility methods
- Host: GitHub
- URL: https://github.com/wschella/asynciteratorasync
- Owner: wschella
- License: mit
- Created: 2018-05-02T09:46:37.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-02T13:04:01.000Z (over 6 years ago)
- Last Synced: 2024-11-10T08:12:26.811Z (10 days ago)
- Language: TypeScript
- Size: 42 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AsyncFilterIterator
An AsyncIterator extensions that allows for filtering with Promise based filters.
Use it like this:
```ts
const oldStream: AsyncIterator = whateverAsyncIteratorYouHadBefore;
const filter: (item: T) => Promise = someFilterYouWantToApply;
const newStream = new AsyncFilterIterator(filter, oldStream);
```The only actual code is this:
```ts
import { AsyncIterator, TransformIterator } from 'asynciterator';export class AsyncFilterIterator extends TransformIterator {
constructor(public _filter: (item: T) => Promise, source: AsyncIterator) {
super({ source });
}_transform(item: T, done: any) {
this._filter(item)
.then((result) => (result) ? this._push(item) : undefined)
.then(() => done())
.catch((error) => {
this.emit('error', error);
done();
});
};
}
```