refactor: add promise helper and change whenReady to be native impl (#13115)
* Add promise helper and change whenReady to be native impl * remove commented code * add GetInner helper to dedupe promise code * add Promise.reject helper to be consistent with JS * fix linting * update promise impl per feedback * remove param name from unused isolate * Use non-depreceated resolvers for promises * Add thread dchecks for promise helper, intiialize promise pointer to nullptr
This commit is contained in:
parent
e9971173d4
commit
92588be2bd
8 changed files with 145 additions and 18 deletions
|
@ -12,30 +12,12 @@ const {deprecate, Menu} = electron
|
|||
const {EventEmitter} = require('events')
|
||||
|
||||
let dockMenu = null
|
||||
let readyPromise = null
|
||||
|
||||
// App is an EventEmitter.
|
||||
Object.setPrototypeOf(App.prototype, EventEmitter.prototype)
|
||||
EventEmitter.call(app)
|
||||
|
||||
Object.assign(app, {
|
||||
whenReady () {
|
||||
if (readyPromise !== null) {
|
||||
return readyPromise
|
||||
}
|
||||
|
||||
if (app.isReady()) {
|
||||
readyPromise = Promise.resolve()
|
||||
} else {
|
||||
readyPromise = new Promise(resolve => {
|
||||
// XXX(alexeykuzmin): Explicitly ignore any data
|
||||
// passed to the event handler to avoid memory leaks.
|
||||
app.once('ready', () => resolve())
|
||||
})
|
||||
}
|
||||
|
||||
return readyPromise
|
||||
},
|
||||
setApplicationMenu (menu) {
|
||||
return Menu.setApplicationMenu(menu)
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue