feat: promisify contentTracing.getTraceBufferUsage() (#16600)

* feat: promsify contentTracing.getTraceBufferUsage()

* deprecate getTraceBufferUsage

* address feedback from review

* properly deprecate
This commit is contained in:
Shelley Vohr 2019-02-13 13:24:57 -08:00 committed by GitHub
parent 9b29befdc8
commit fed5b99a9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 7 deletions

View file

@ -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)