Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: setTimeout cannot be util.promisify'ed (backport: 1-8-x) #13858

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/common/init.js
Original file line number Diff line number Diff line change
@@ -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,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) {
return function () {
process.activateUvLoop()
return func.apply(this, arguments)
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)
Expand Down
4 changes: 4 additions & 0 deletions spec/node-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,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