declare module "interfaces" { /** * The signature of resolve function for Promise. */ export interface PromiseResolver { (val?: T): void; } /** * The signature of reject function for Promise. */ export interface PromiseRejector { (err: T): void; } /** * Type for the string-index dictionary object. */ export interface Dictionary { [key: string]: T; } /** * Type for the number-index dictionary object. */ export interface NumericDictionary { [key: number]: T; } /** * The signature of a no data bound asynchronous callback. */ export interface AsyncErrorCallback { (error?: E): void; } /** * The signature of a no data bound asynchronous callback. */ export interface RetryCallback { (error?: E, quit?: boolean): void; } /** * The signature of a data bound asynchronous callback. */ export interface SeriesNextCallback { (error?: E, ...args: any[]): void; } /** * The signature of simple functions for controlling callback. */ export interface SeriesFunction { (next: SeriesNextCallback, ...args: any[]): void; } /** * The signature of the iterator function of list.forEach. */ export interface ForEachIterator { (val: T, key: string | number, next: AsyncErrorCallback): void; } /** * The signature of the next callback function of list.map. */ export interface MapNextCallback { (error: E, val?: T): void; } /** * The signature of the result callback of list.map. */ export interface MapResultCallback { (error: E, vals?: Dictionary | T[]): void; } /** * The signature of the iterator function of list.map. */ export interface MapIterator { (val: T, key: string | number, next: MapNextCallback): void; } export interface ISetNextTick { (fn: Function, ...args: any[]): void; } /** * The signature of simple functions for controlling callback. */ export interface SimpleFunction { (next: AsyncErrorCallback): void; } export interface FlowNextCallback { (next: string, error?: E, ...args: any[]): void; } export interface FlowFunction { (next: FlowNextCallback, ...args: any[]): void; } export interface ParallelCallback { (err?: NumericDictionary): void; } export interface SyncConditionTester { (): boolean; } export interface BooleanCallback { (result: boolean): void; } export interface ConditionTester { (cb: BooleanCallback): void; } /** * The signature for worker function of retry. * * The second parameter tells the sequence for retrying. * And sequence === 0 means the first time before retrying. */ export interface RetryWorker { (next: RetryCallback, sequence: number): void; } export type RepeatWorker = RetryWorker; } declare module "common" { import { ISetNextTick } from "interfaces"; export let setNextTick: ISetNextTick; /** * Wrap and limit a function to be called only once. */ export function once(callback: T): T; } declare module "classes/RawPromise" { import { PromiseResolver, PromiseRejector } from "interfaces"; export class RawPromise { resolve: PromiseResolver; reject: PromiseRejector; promise: Promise; constructor(); } } declare module "list/forEach" { import { ForEachIterator, AsyncErrorCallback, Dictionary, ParallelCallback } from "interfaces"; /** * This method enum all items in an array or an object one by one, * with index value. */ export function series(data: Dictionary | T[], next: ForEachIterator, final: AsyncErrorCallback): void; /** * This method enum all items in an array or an object at once, * with index value. */ export function parallel(data: Dictionary | T[], next: ForEachIterator, final: ParallelCallback): void; export function forEach_Promise(data: Dictionary | T[], next: ForEachIterator): Promise; } declare module "list/map" { import { MapIterator, Dictionary, MapResultCallback } from "interfaces"; /** * This method enum all items in an array or an object one by one, * with index value. */ export function series(data: Dictionary | T[], next: MapIterator, final: MapResultCallback): void; export function series_Promise(data: Dictionary | T[], next: MapIterator): Promise; } declare module "promise" { export { forEach_Promise as forEach } from "list/forEach"; } declare module "control/series" { import { SeriesNextCallback, SeriesFunction } from "interfaces"; /** * This method executes a series of functions one by one in order, or break * if an error occured. Finally, the final callback will be call, with the * ending reason if exists. */ export function series(fns: SeriesFunction[], final?: SeriesNextCallback): void; } declare module "control/flow" { import { AsyncErrorCallback, FlowFunction, Dictionary } from "interfaces"; export function flow(start: string, fns: Dictionary>, final?: AsyncErrorCallback): void; } declare module "control/forever" { import { AsyncErrorCallback, SimpleFunction } from "interfaces"; /** * This method executes a loop body until an error occured. */ export function forever(loopBody: SimpleFunction, final?: AsyncErrorCallback): void; } declare module "control/repeat" { import { AsyncErrorCallback, RepeatWorker } from "interfaces"; /** * This method will executes a loop body for N times, or until it meets a * failure. */ export function repeat(times: number, loopBody: RepeatWorker, final?: AsyncErrorCallback): void; } declare module "control/retry" { import { AsyncErrorCallback, RetryWorker } from "interfaces"; /** * This method executes a function once, and then retry executing it N times * while it still failing. * * It means the function will be executed at least 1 time and at most N+1 * times. */ export function retry(times: number, mainBody: RetryWorker, final?: AsyncErrorCallback): void; } declare module "control/whileIf" { import { AsyncErrorCallback, SyncConditionTester, SimpleFunction } from "interfaces"; /** * This method executes a loop body until the condition function returns false. */ export function whileIf(condition: SyncConditionTester, loopBody: SimpleFunction, final?: AsyncErrorCallback): void; } declare module "control/whileUntil" { import { AsyncErrorCallback, SyncConditionTester, SimpleFunction } from "interfaces"; /** * This method executes a loop body until the condition function returns true. */ export function whileUntil(loopBody: SimpleFunction, condition: SyncConditionTester, final?: AsyncErrorCallback): void; } declare module "control/loopIf" { import { AsyncErrorCallback, ConditionTester, SimpleFunction } from "interfaces"; /** * This method executes a loop body until the condition function returns false. */ export function loopIf(condition: ConditionTester, loopBody: SimpleFunction, final?: AsyncErrorCallback): void; } declare module "control/loopUntil" { import { AsyncErrorCallback, ConditionTester, SimpleFunction } from "interfaces"; /** * This method executes a loop body until the condition function returns true. */ export function loopUntil(loopBody: SimpleFunction, condition: ConditionTester, final?: AsyncErrorCallback): void; } declare module "control/parallel" { import { SimpleFunction, ParallelCallback } from "interfaces"; /** * This method executes a series of functions at once, and wait for the results * thereof. */ export function parallel(fns: SimpleFunction[], final?: ParallelCallback): void; } declare module "control/concurrent" { import { SimpleFunction, ParallelCallback } from "interfaces"; /** * This method starts functions in a series at once, but at most N functions, * should be executing in the same moment. And then executes the rest in * series in sequence. */ export function concurrent(currency: number, fns: SimpleFunction[], final?: ParallelCallback): void; } declare module "index" { export let version: string; export * from "interfaces"; export * from "classes/RawPromise"; import * as forEach from "list/forEach"; import * as map from "list/map"; export import promise = require("promise"); export { series } from "control/series"; export { flow } from "control/flow"; export { forever } from "control/forever"; export { repeat } from "control/repeat"; export { retry } from "control/retry"; export { whileIf } from "control/whileIf"; export { whileUntil } from "control/whileUntil"; export { loopIf } from "control/loopIf"; export { loopUntil } from "control/loopUntil"; export { parallel } from "control/parallel"; export { concurrent } from "control/concurrent"; export { setNextTick, once } from "common"; export { forEach, map }; }