Skip to content

on('connect') documentation update #42

@aarongeorge

Description

@aarongeorge

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions