You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m encountering an issue with handling multiple user interaction options in my application. Specifically, I want to allow users to interact via either callbackQueries or messages. To achieve this, I’ve been using Promise.race([Promise1, Promise2]) to wait for the first resolved interaction.
The issue occurs after several conversational flows, where unused listeners appear to linger in the event loop, delaying the triggering of the next interaction. As a result, I have to repeat the unused interaction multiple times before the current listener is activated.
I suspect this might be a bug, but it would also be great if a feature for handling multiple conversation choices could be added.
Thanks for your time, and I look forward to your insights on this!
The text was updated successfully, but these errors were encountered:
It is not a good idea to use Promise.race for this. A wait call will always wait for an update, no matter if you use this update or not. By design, Promise.race throws away the results of all promises but the first one to resolve. This means that your code will wait for updates and then swallow them.
This is explained in more detail at #1190. I also added a code example there.
A better idea to wait for either a callback query or a message is to do
KnorpelSenf
changed the title
Issue with Concurrent Listeners in Promise.race and Event Loop Behavior
Document issues with Concurrent Listeners in Promise.race and Event Loop Behavior
Feb 14, 2025
Hi,
I’m encountering an issue with handling multiple user interaction options in my application. Specifically, I want to allow users to interact via either
callbackQueries
ormessages
. To achieve this, I’ve been usingPromise.race([Promise1, Promise2])
to wait for the first resolved interaction.The issue occurs after several conversational flows, where unused listeners appear to linger in the event loop, delaying the triggering of the next interaction. As a result, I have to repeat the unused interaction multiple times before the current listener is activated.
I suspect this might be a bug, but it would also be great if a feature for handling multiple conversation choices could be added.
Thanks for your time, and I look forward to your insights on this!
The text was updated successfully, but these errors were encountered: