@enterprise_search/kleislis
Advanced tools
Comparing version 0.8.9 to 0.8.10
@@ -7,3 +7,5 @@ import { ConcurrencyLimits } from "./concurrency.limiter"; | ||
export declare function asyncSource<T>(source: T[]): AsyncGenerator<T>; | ||
export declare function mapAsync<T, R>(generator: AsyncGenerator<T>, mapFunc: (value: T) => Promise<R>, config: AsyncConfig): Promise<R[]>; | ||
export declare function asyncTestSource<T>(n: number, generatorFunc: (i: number) => T): AsyncGenerator<T>; | ||
export declare function mapAsyncToAsync<T, R>(generator: AsyncGenerator<T>, mapFunc: (value: T, count: number) => Promise<R>): AsyncGenerator<R>; | ||
export declare function mapAsync<T, R>(generator: AsyncGenerator<T>, mapFunc: (value: T, count: number) => Promise<R>, config: AsyncConfig): Promise<R[]>; | ||
export declare function collectAsync<T, R>(generator: AsyncGenerator<T>, filterFunc: (value: T) => boolean, mapFunc: (value: T) => Promise<R>, config: AsyncConfig): Promise<R[]>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.asyncSource = asyncSource; | ||
exports.asyncTestSource = asyncTestSource; | ||
exports.mapAsyncToAsync = mapAsyncToAsync; | ||
exports.mapAsync = mapAsync; | ||
@@ -13,2 +15,13 @@ exports.collectAsync = collectAsync; | ||
} | ||
async function* asyncTestSource(n, generatorFunc) { | ||
for (let i = 0; i < n; i++) { | ||
yield generatorFunc(i); | ||
} | ||
} | ||
async function* mapAsyncToAsync(generator, mapFunc) { | ||
let count = 0; | ||
for await (const value of generator) { | ||
yield await mapFunc(value, count++); | ||
} | ||
} | ||
async function mapAsync(generator, mapFunc, config) { | ||
@@ -18,2 +31,3 @@ const promises = []; | ||
let finished = false; | ||
let count = 0; | ||
return new Promise(async (resolve, reject) => { | ||
@@ -33,3 +47,3 @@ async function addPromise() { | ||
active++; | ||
promises.push(mapFunc(value).finally(() => { | ||
promises.push(mapFunc(value, count++).finally(() => { | ||
active--; | ||
@@ -36,0 +50,0 @@ setImmediate(addPromise); |
{ | ||
"name": "@enterprise_search/kleislis", | ||
"description": "functions that have inputs, returns promises, and non functionals around them", | ||
"version": "0.8.9", | ||
"version": "0.8.10", | ||
"main": "dist/index", | ||
@@ -6,0 +6,0 @@ "types": "dist/index", |
Sorry, the diff of this file is not supported yet
140629
1803