Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/async/compose/docs/types/index.d"

Index

Type aliases

BinaryFunction

BinaryFunction: (result: any, next: DoneCallback) => void

Binary function to compose.

param

result

param

invoked upon function completion

Type declaration

CompositeFunction

CompositeFunction: (...args: Array<any>) => void

Composite function.

param

arguments

param

callback to invoke after invoking all functions

Type declaration

    • (...args: Array<any>): void
    • Parameters

      • Rest ...args: Array<any>

      Returns void

DoneBinary

DoneBinary: (error: Error | null, result: any) => void

Callback invoked upon function completion.

param

error argument

param

function result

Type declaration

    • (error: Error | null, result: any): void
    • Parameters

      • error: Error | null
      • result: any

      Returns void

DoneCallback

DoneCallback: DoneNullary | DoneUnary | DoneBinary

Callback invoked upon function completion.

param

error argument

param

function result

DoneNullary

DoneNullary: () => void

Callback invoked upon function completion.

Type declaration

    • (): void
    • Returns void

DoneUnary

DoneUnary: (error: Error | null) => void

Callback invoked upon function completion.

param

error argument

Type declaration

    • (error: Error | null): void
    • Parameters

      • error: Error | null

      Returns void

VariadicFunction

VariadicFunction: (...args: Array<any>) => void

Function to compose.

Notes

  • Only the rightmost function is explicitly permitted to accept multiple arguments. All other functions are evaluated as binary functions.
param

arguments

param

invoked upon function completion

Type declaration

    • (...args: Array<any>): void
    • Parameters

      • Rest ...args: Array<any>

      Returns void

Functions

Export assignment composeAsync

  • Function composition.

    Notes

    • Returns a composite function. Starting from the right, the composite function evaluates each function and passes the result as the first argument of the next function. The result of the leftmost function is the result of the whole.

    Parameters

    Returns CompositeFunction

    composite function

    Example

    function a( x, next ) {
        setTimeout( onTimeout, 0 );
        function onTimeout() {
            next( null, 2*x );
        }
    }
    
    function b( x, next ) {
        setTimeout( onTimeout, 0 );
        function onTimeout() {
            next( null, x+3 );
        }
    }
    
    function c( x, next ) {
        setTimeout( onTimeout, 0 );
        function onTimeout() {
            next( null, x/5 );
        }
    }
    
    var f = composeAsync( c, b, a );
    
    function done( error, result ) {
        if ( error ) {
            throw error;
        }
        console.log( result );
        // => 3
    }
    
    f( 6, done );