nope-js-browser
Version:
NoPE Runtime for the Browser. For nodejs please use nope-js-node
77 lines (76 loc) • 2.34 kB
TypeScript
/**
* @author Martin Karkowski
* @email m.karkowski@zema.de
*/
/// <reference types="node" />
import { EventEmitter } from "events";
import { LoggerLevel } from "../index.browser";
/**
* The options for call
*/
export type TLimitedOptions = {
/**
* The Id to use. If not provided, an specific id is generated
*/
functionId: string;
/**
* An queue that should be used. If not provided, a queue is used.
*/
queue: Array<[string, string, any[]]>;
/**
* Mapping for the Functions.
*/
mapping: {
[index: string]: (...args: any[]) => Promise<any>;
};
/**
* An emitter to use.
*/
emitter: EventEmitter;
/**
* Helper function to request a lock.
*/
getLock: (functionId: string, newTaskId: string) => boolean;
/**
* An additional function, wich can be used between the next function in is called. e.g. sleep.
*/
callbackBetween?: () => Promise<void>;
/**
* Number of elements, which could be called in parallel. 0 = sequntial
*/
maxParallel: number;
/**
* A logger to use.
*/
loggerLevel: false | LoggerLevel;
/**
* An overview with active Tasks. This is relevant for multiple Funtions.
*/
activeTasks: Set<string>;
/**
* An overview with active Tasks. This is relevant for multiple Funtions.
*/
awaitingTasks: Set<string>;
/**
* Helper to assign the control function, for example on an async function.
*/
assignControlFunction: (args: any[], functions: {
pauseTask: () => void;
continueTask: () => void;
}) => any[];
minDelay: number;
lastDone: number;
};
/**
* Helper to get the default options in a shared context
* @param options The options to enhance the defaults.
* @returns The options.
*/
export declare function getLimitedOptions(options: Partial<TLimitedOptions>): Partial<TLimitedOptions>;
/**
* Function to limit the calls based on the settings.
* @param func The function to use. This should be an async function.
* @param options The Options.
* @returns
*/
export declare function limitedCalls<T>(func: (...args: any[]) => Promise<T>, options: Partial<TLimitedOptions>): (...args: any[]) => Promise<T>;