strong-tie/inbound-calls
0
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 