@enterprise_search/kleislis
Advanced tools
Comparing version 0.5.5 to 0.6.0
import { ConcurrencyLimits } from "./concurrency.limiter"; | ||
export declare function tryAndAddTask<T, R>(generator: AsyncGenerator<T>, concurrencyLimits: ConcurrencyLimits, mapFunc: (value: T) => Promise<R>, results: Promise<R>[]): Promise<boolean>; | ||
export type AsyncConfig = { | ||
@@ -7,3 +6,4 @@ concurrencyLimits: ConcurrencyLimits; | ||
}; | ||
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 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.collectAsync = exports.mapAsync = exports.tryAndAddTask = void 0; | ||
async function tryAndAddTask(generator, concurrencyLimits, mapFunc, results) { | ||
if (concurrencyLimits.queue.length === 0) { | ||
const { value, done } = await generator.next(); | ||
if (!done) { | ||
results.push(mapFunc(value)); | ||
} | ||
return done; | ||
exports.collectAsync = exports.mapAsync = exports.asyncSource = void 0; | ||
async function* asyncSource(source) { | ||
for (const value of source) { | ||
yield value; | ||
} | ||
return false; //Not done | ||
} | ||
exports.tryAndAddTask = tryAndAddTask; | ||
exports.asyncSource = asyncSource; | ||
async function mapAsync(generator, mapFunc, config) { | ||
@@ -16,0 +11,0 @@ const promises = []; |
{ | ||
"name": "@enterprise_search/kleislis", | ||
"description": "functions that have inputs, returns promises, and non functionals around them", | ||
"version": "0.5.5", | ||
"version": "0.6.0", | ||
"main": "dist/index", | ||
@@ -6,0 +6,0 @@ "types": "dist/index", |
75762
1580