feat: promisify contentTracing.getTraceBufferUsage() (#16600)
* feat: promsify contentTracing.getTraceBufferUsage() * deprecate getTraceBufferUsage * address feedback from review * properly deprecate
This commit is contained in:
parent
9b29befdc8
commit
fed5b99a9f
6 changed files with 72 additions and 7 deletions
|
@ -104,6 +104,32 @@ const deprecate = {
|
|||
}
|
||||
},
|
||||
|
||||
promisifyMultiArg: (fn) => {
|
||||
const fnName = fn.name || 'function'
|
||||
const oldName = `${fnName} with callbacks`
|
||||
const newName = `${fnName} with Promises`
|
||||
const warn = warnOnce(oldName, newName)
|
||||
|
||||
return function (...params) {
|
||||
let cb
|
||||
if (params.length > 0 && typeof params[params.length - 1] === 'function') {
|
||||
cb = params.pop()
|
||||
}
|
||||
const promise = fn.apply(this, params)
|
||||
if (!cb) return promise
|
||||
if (process.enablePromiseAPIs) warn()
|
||||
return promise
|
||||
.then(res => {
|
||||
process.nextTick(() => {
|
||||
// eslint-disable-next-line standard/no-callback-literal
|
||||
cb.length > 2 ? cb(null, ...res) : cb(...res)
|
||||
})
|
||||
}, err => {
|
||||
process.nextTick(() => cb(err))
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
renameProperty: (o, oldName, newName) => {
|
||||
const warn = warnOnce(oldName, newName)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue