ElijahPepe Posted August 20, 2022 Report Posted August 20, 2022 I have two functions in a class: login(username, password) { this.steamUser.logOn({ accountName: username, password: password }); this.steamUser.on('loggedOn', async () => { await this._getAccessToken(); return this.accessToken; }); } _getAccessToken() { return new Promise(resolve => { this.steamUser.getEncryptedAppTicket(1818750, async (err, appTicket) => { if (err) { throw new Error(err); } const data = await this.info(appTicket.toString('hex').toUpperCase()); this.accessToken = data.token; resolve(this); }); }); } When I call the login() function, .logOn() is resolved before the loggedOn event can be fired. Is there a way of using .logOn() asynchronously? Quote
Dr. McKay Posted August 21, 2022 Report Posted August 21, 2022 You would need to wrap logOn and the loggedOn handler in a promise. You'd also need to account for the error event in case you fail to log on, and remove the event listeners when you resolve the promise. Quote
Rodrigo Posted September 16, 2022 Report Posted September 16, 2022 I was wondering, wouldn't the logOff() method remove the event listeners? @Dr. McKay Quote
Dr. McKay Posted September 16, 2022 Report Posted September 16, 2022 No, you're responsible for removing your own event listeners. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.