Skip to content

Commit

Permalink
fix: util.promisify(setTimeout)
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Jul 29, 2018
1 parent a6bc803 commit ccc81a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/common/init.js
@@ -1,4 +1,5 @@
const timers = require('timers')
const util = require('util')

process.atomBinding = require('./atom-binding-setup')(process.binding, process.type)

Expand All @@ -8,11 +9,18 @@ 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) {
return function () {
const wrapWithActivateUvLoop = function (func) {
const wrapped = function () {
process.activateUvLoop()
return func.apply(this, arguments)
}
if (func[util.promisify.custom]) {
wrapped[util.promisify.custom] = function () {
process.activateUvLoop()
return func[util.promisify.custom].apply(this, arguments)
}
}
return wrapped
}

process.nextTick = wrapWithActivateUvLoop(process.nextTick)
Expand Down
4 changes: 4 additions & 0 deletions spec/node-spec.js
Expand Up @@ -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', () => {
Expand Down
2 changes: 2 additions & 0 deletions spec/static/main.js
Expand Up @@ -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')
})
Expand Down

0 comments on commit ccc81a4

Please sign in to comment.