generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
Hi, I would know where was this project ? I'm very interested in this specs as it would solve many problems js developers face with generator used as "data receiver" instead of "data emiter" (or both).
I may share another very practical use case of function.sent:
export interface IGetPaginatedDataOptions {
signal?: AbortSignal;
}
export class Pagination<GData> {
getPaginatedData(page: IPageInfo, options?: IGetPaginatedDataOptions): Promise<IPaginatedData<GData>> {
return fetch('some url', options).then(_ => _.json());
}
/**
* Creates an async iterator over the list of pages
*/
async* pageIterator({ pageIndex = 0, itemsPerPage = 10 }: Partial<IPageInfo> = {}): AsyncGenerator<IPaginatedData<GData>, any, any> {
const page: IPageInfo = { pageIndex, itemsPerPage };
let result: IPaginatedData<GData>;
do {
result = await this.getPaginatedData(page, function.sent); // note just here the usage of funtion.sent
yield result;
page.pageIndex++;
} while (result.pageCount > page.pageIndex);
}
}
const pagination = new Pagination().pageIterator();
const controller = new AbortController();
setTimeout(() => controller.abort('timeout'), 5000);
const page = await pagination.next(controller);It could be extremely useful for AsyncIterators ! Hope it's not dead ?
Metadata
Metadata
Assignees
Labels
No labels