fatsify核心功能示例测试!!!
This commit is contained in:
28
node_modules/avvio/lib/execute-with-thenable.js
generated
vendored
Normal file
28
node_modules/avvio/lib/execute-with-thenable.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict'
|
||||
const { isPromiseLike } = require('./is-promise-like')
|
||||
const { kAvvio } = require('./symbols')
|
||||
|
||||
/**
|
||||
* @callback ExecuteWithThenableCallback
|
||||
* @param {Error} error
|
||||
* @returns {void}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {Function} func
|
||||
* @param {Array<any>} args
|
||||
* @param {ExecuteWithThenableCallback} [callback]
|
||||
*/
|
||||
function executeWithThenable (func, args, callback) {
|
||||
const result = func.apply(func, args)
|
||||
if (isPromiseLike(result) && !result[kAvvio]) {
|
||||
// process promise but not avvio mock thenable
|
||||
result.then(() => process.nextTick(callback), (error) => process.nextTick(callback, error))
|
||||
} else if (callback) {
|
||||
process.nextTick(callback)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
executeWithThenable
|
||||
}
|
||||
Reference in New Issue
Block a user