CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
execute-with-thenable.js29 linesDownload Raw Back to lib
1'use strict'2const { isPromiseLike } = require('./is-promise-like')3const { kAvvio } = require('./symbols')4 5/**6 * @callback ExecuteWithThenableCallback7 * @param {Error} error8 * @returns {void}9 */10 11/**12 * @param {Function} func13 * @param {Array<any>} args14 * @param {ExecuteWithThenableCallback} [callback]15 */16function executeWithThenable (func, args, callback) {17  const result = func.apply(func, args)18  if (isPromiseLike(result) && !result[kAvvio]) {19    // process promise but not avvio mock thenable20    result.then(() => process.nextTick(callback), (error) => process.nextTick(callback, error))21  } else if (callback) {22    process.nextTick(callback)23  }24}25 26module.exports = {27  executeWithThenable28}29