Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

12345678910111213141516171819202122232425262728293031323334
  1. var defer = require('./defer.js');
  2. // API
  3. module.exports = async;
  4. /**
  5. * Runs provided callback asynchronously
  6. * even if callback itself is not
  7. *
  8. * @param {function} callback - callback to invoke
  9. * @returns {function} - augmented callback
  10. */
  11. function async(callback)
  12. {
  13. var isAsync = false;
  14. // check if async happened
  15. defer(function() { isAsync = true; });
  16. return function async_callback(err, result)
  17. {
  18. if (isAsync)
  19. {
  20. callback(err, result);
  21. }
  22. else
  23. {
  24. defer(function nextTick_callback()
  25. {
  26. callback(err, result);
  27. });
  28. }
  29. };
  30. }