ElijahPepe Posted August 20, 2022 Report Share 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 Link to comment Share on other sites More sharing options...
Dr. McKay Posted August 21, 2022 Report Share 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 Link to comment Share on other sites More sharing options...
Rodrigo Posted September 16, 2022 Report Share Posted September 16, 2022 I was wondering, wouldn't the logOff() method remove the event listeners? @Dr. McKay Quote Link to comment Share on other sites More sharing options...
Dr. McKay Posted September 16, 2022 Report Share Posted September 16, 2022 No, you're responsible for removing your own event listeners. Quote Link to comment Share on other sites More sharing options...
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.