time-to-botec

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

index.js (1083B)


      1 'use strict';
      2 
      3 if (typeof process === 'undefined' ||
      4     !process.version ||
      5     process.version.indexOf('v0.') === 0 ||
      6     process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) {
      7   module.exports = { nextTick: nextTick };
      8 } else {
      9   module.exports = process
     10 }
     11 
     12 function nextTick(fn, arg1, arg2, arg3) {
     13   if (typeof fn !== 'function') {
     14     throw new TypeError('"callback" argument must be a function');
     15   }
     16   var len = arguments.length;
     17   var args, i;
     18   switch (len) {
     19   case 0:
     20   case 1:
     21     return process.nextTick(fn);
     22   case 2:
     23     return process.nextTick(function afterTickOne() {
     24       fn.call(null, arg1);
     25     });
     26   case 3:
     27     return process.nextTick(function afterTickTwo() {
     28       fn.call(null, arg1, arg2);
     29     });
     30   case 4:
     31     return process.nextTick(function afterTickThree() {
     32       fn.call(null, arg1, arg2, arg3);
     33     });
     34   default:
     35     args = new Array(len - 1);
     36     i = 0;
     37     while (i < args.length) {
     38       args[i++] = arguments[i];
     39     }
     40     return process.nextTick(function afterTick() {
     41       fn.apply(null, args);
     42     });
     43   }
     44 }
     45