Callback function.
Function to invoke if x
returns an error.
First function to invoke.
Function to invoke if x
returns an error.
If a function does not return an error, invokes a callback with the function result; otherwise, invokes a second function y
.
function to invoke
function to invoke if x
returns an error
callback to invoke upon completion
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 );
Function to invoke if
x
returns an error.the error from
x
callback to invoke upon function completion