Function to invoke.
If a function does not return an error, invokes a callback with the function result; otherwise, invokes a callback with a value y
.
function to invoke
value to return 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 done( error, result ) {
if ( error ) {
console.log( error.message );
}
console.log( result );
}
trycatchAsync( x, -1.0, done );
Callback function.
encountered error or null
either the result of
x
or the provided argumenty