Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Type aliases

Binary

Binary: (error: Error, clbk: Callback) => void

Function to invoke if x returns an error.

param

the error from x

param

callback to invoke upon function completion

Type declaration

    • Parameters

      Returns void

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

ThenFunction

ThenFunction: Unary | Binary

Function to invoke if x returns an error.

param

the error from x

param

callback to invoke upon function completion

TryFunction

TryFunction: (clbk: Callback) => void

First function to invoke.

param

callback to invoke upon function completion

Type declaration

Unary

Unary: (clbk: Callback) => void

Function to invoke if x returns an error.

param

callback to invoke upon function completion

Type declaration

Functions

Export assignment trythenAsync

  • If a function does not return an error, invokes a callback with the function result; otherwise, invokes a second function y.

    Parameters

    Returns void

    Example

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