fix: util.promisify(setTimeout) (#13840)
This commit is contained in:
parent
db38c8b620
commit
39c5c200ba
3 changed files with 21 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
|||
const timers = require('timers')
|
||||
const util = require('util')
|
||||
|
||||
process.atomBinding = require('./atom-binding-setup')(process.binding, process.type)
|
||||
|
||||
|
@ -8,11 +9,21 @@ process.atomBinding = require('./atom-binding-setup')(process.binding, process.t
|
|||
// which would delay the callbacks for arbitrary long time. So we should
|
||||
// initiatively activate the uv loop once setImmediate and process.nextTick is
|
||||
// called.
|
||||
var wrapWithActivateUvLoop = function (func) {
|
||||
const wrapWithActivateUvLoop = function (func) {
|
||||
return wrap(func, function (func) {
|
||||
return function () {
|
||||
process.activateUvLoop()
|
||||
return func.apply(this, arguments)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function wrap (func, wrapper) {
|
||||
const wrapped = wrapper(func)
|
||||
if (func[util.promisify.custom]) {
|
||||
wrapped[util.promisify.custom] = wrapper(func[util.promisify.custom])
|
||||
}
|
||||
return wrapped
|
||||
}
|
||||
|
||||
process.nextTick = wrapWithActivateUvLoop(process.nextTick)
|
||||
|
|
|
@ -179,6 +179,10 @@ describe('node feature', () => {
|
|||
it('can be scheduled in time', (done) => {
|
||||
remote.getGlobal('setTimeout')(done, 0)
|
||||
})
|
||||
|
||||
it('can be promisified', (done) => {
|
||||
remote.getGlobal('setTimeoutPromisified')(0).then(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('setInterval called under Chromium event loop in browser process', () => {
|
||||
|
|
|
@ -79,6 +79,8 @@ ipcMain.on('echo', function (event, msg) {
|
|||
event.returnValue = msg
|
||||
})
|
||||
|
||||
global.setTimeoutPromisified = util.promisify(setTimeout)
|
||||
|
||||
const coverage = new Coverage({
|
||||
outputPath: path.join(__dirname, '..', '..', 'out', 'coverage')
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue