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 28, 2018
1 parent a6bc803 commit 33715a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 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 Down Expand Up @@ -28,6 +29,12 @@ if (process.type === 'browser') {
// recalculate the timeout in browser process.
global.setTimeout = wrapWithActivateUvLoop(timers.setTimeout)
global.setInterval = wrapWithActivateUvLoop(timers.setInterval)

global.setTimeout[util.promisify.custom] = function (timeout) {
return new Promise(resolve => {
global.setTimeout(resolve, timeout)
})
}
}

if (process.platform === 'win32') {
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 33715a5

Please sign in to comment.