-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
I ran into this recently and think it might be useful to add to the docs that the on('connect') callback will only fire AFTER you make a call (I make a dummy call to org.rdk.System.getDeviceInfo).
This problem becomes apparent when the on('connect') callback needs to handle async functions before anything else is executed.
class CustomClass {
constructor () {
this.thunderJS = ThunderJS({ host: '127.0.0.1', port: 9998 })
}
init () {
return new Promise((resolve, reject) => {
this.thunderJS.on('connect', () => {
console.log('connected') // In the real world this would be some async functions
return resolve()
})
// Dummy call required to trigger the connect callback (without it it will never fire)
const dummyCall = await this.thunderJS.call('org.rdk.System', 'getDeviceInfo')
})
}
}
;(async () => {
const cc = new CustomClass()
await cc.init()
console.log('finished loading') // Will log if dummyCall exists, but won't if commented out
})()Metadata
Metadata
Assignees
Labels
No labels