Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Index

Type aliases

Functions

Type aliases

Callback

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

Callback function.

param

encountered error or null

param

either the result of x or the provided argument y

Type declaration

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

      • error: Error | null
      • result: any

      Returns void

TryFunction

TryFunction: (clbk: Callback) => void

Function to invoke.

param

callback to invoke upon function completion

Type declaration

Functions

Export assignment trycatchAsync

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

    Parameters

    • x: TryFunction

      function to invoke

    • y: any

      value to return if x returns an error

    • done: Callback

      callback to invoke upon completion

    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 done( error, result ) {
        if ( error ) {
            console.log( error.message );
        }
        console.log( result );
    }
    
    trycatchAsync( x, -1.0, done );