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

on('connect') documentation update #42

Open
aarongeorge opened this issue May 15, 2024 · 0 comments
Open

on('connect') documentation update #42

aarongeorge opened this issue May 15, 2024 · 0 comments

Comments

@aarongeorge
Copy link

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
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant