time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

repl.txt (2427B)


      1 
      2 {{alias}}( x, y, done )
      3     If a function does not return an error, invokes a callback with the function
      4     result; otherwise, invokes a second function `y`.
      5 
      6     A function `x` is provided a single argument:
      7 
      8     - clbk: callback to invoke upon function completion
      9 
     10     The callback function accepts any number of arguments, with the first
     11     argument reserved for providing an error.
     12 
     13     If the error argument is falsy, the function invokes a `done` callback with
     14     its first argument as `null` and all other provided arguments.
     15 
     16     If the error argument is truthy, the function invokes a function `y`. The
     17     number of arguments provided to `y` depends on the function's length. If `y`
     18     is a unary function, `y` is provided a single argument:
     19 
     20     - clbk: callback to invoke upon function completion
     21 
     22     Otherwise, `y` is provided two arguments:
     23 
     24     - error: the error from `x`
     25     - clbk: callback to invoke upon function completion
     26 
     27     The callback function accepts any number of arguments, with the first
     28     argument reserved for providing an error.
     29 
     30     If the error argument is falsy, the `done` callback is invoked with its
     31     first argument equal to `null` and all other arguments provided by `y`.
     32 
     33     If the error argument is truthy, the `done` callback is invoked with only
     34     the error argument provided by `y`.
     35 
     36     Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
     37     wrap the `done` callback in a function which either executes at the end of
     38     the current stack (e.g., `nextTick`) or during a subsequent turn of the
     39     event loop (e.g., `setImmediate`, `setTimeout`).
     40 
     41     Parameters
     42     ----------
     43     x: Function
     44         Function to invoke.
     45 
     46     y: Function
     47         Function to invoke if `x` returns an error.
     48 
     49     done: Function
     50         Callback to invoke upon completion.
     51 
     52     Examples
     53     --------
     54     > function x( clbk ) {
     55     ...     setTimeout( onTimeout, 0 );
     56     ...     function onTimeout() {
     57     ...         clbk( new Error( 'beep' ) );
     58     ...     }
     59     ... };
     60     > function y( clbk ) {
     61     ...     setTimeout( onTimeout, 0 );
     62     ...     function onTimeout() {
     63     ...         clbk( null, 'boop' );
     64     ...     }
     65     ... };
     66     > function done( error, result ) {
     67     ...     if ( error ) {
     68     ...         throw error;
     69     ...     }
     70     ...     console.log( result );
     71     ... };
     72     > {{alias}}( x, y, done )
     73     'boop'
     74 
     75     See Also
     76     --------
     77