Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "utils/async/if-then/docs/types/index.d"

Index

Type aliases

Callback

Callback: (error: Error | null, ...args: Array<any>) => void

Callback function.

param

encountered error or null

param

results

Type declaration

    • (error: Error | null, ...args: Array<any>): void
    • Parameters

      • error: Error | null
      • Rest ...args: Array<any>

      Returns void

Predicate

Predicate: (clbk: PredicateCallback) => void

Predicate function.

param

callback to invoke upon predicate function completion

Type declaration

PredicateBinary

PredicateBinary: (error: Error, bool: boolean) => void

Predicate callback function.

param

error object

param

condition used to determine whether to invoke x or y

Type declaration

    • (error: Error, bool: boolean): void
    • Parameters

      • error: Error
      • bool: boolean

      Returns void

PredicateCallback

Predicate callback function.

param

error object

param

condition used to determine whether to invoke x or y

PredicateNullary

PredicateNullary: () => void

Predicate callback function.

Type declaration

    • (): void
    • Returns void

PredicateUnary

PredicateUnary: (error: Error) => void

Predicate callback function.

param

error object

Type declaration

    • (error: Error): void
    • Parameters

      • error: Error

      Returns void

ResultFunction

ResultFunction: (clbk: Callback) => void

Function invoked after condition check.

param

callback to invoke upon function completion

Type declaration

Functions

Export assignment ifthenAsync

  • If a predicate function returns a truthy value, invokes x; otherwise, invokes y.

    Parameters

    Returns void

    Example

    var randu = require( `@stdlib/random/base/randu` );
    
    function predicate( clbk ) {
        setTimeout( onTimeout, 0 );
        function onTimeout() {
            clbk( null, randu() > 0.5 );
        }
    }
    
    function x( clbk ) {
        setTimeout( onTimeout, 0 );
        function onTimeout() {
            clbk( null, 1.0 );
        }
    }
    
    function y( clbk ) {
        setTimeout( onTimeout, 0 );
        function onTimeout() {
            clbk( null, -1.0 );
        }
    }
    
    function done( error, result ) {
        if ( error ) {
            throw error;
        }
        console.log( result );
    }
    ifthenAsync( predicate, x, y, done );