Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
async.js35 linesDownload Raw Back to lib
1var defer = require('./defer.js');2 3// API4module.exports = async;5 6/**7 * Runs provided callback asynchronously8 * even if callback itself is not9 *10 * @param   {function} callback - callback to invoke11 * @returns {function} - augmented callback12 */13function async(callback)14{15  var isAsync = false;16 17  // check if async happened18  defer(function() { isAsync = true; });19 20  return function async_callback(err, result)21  {22    if (isAsync)23    {24      callback(err, result);25    }26    else27    {28      defer(function nextTick_callback()29      {30        callback(err, result);31      });32    }33  };34}35 
codekingpro/portable-devtools · Team Ai