Does anyone else find approach #3 to be wildly unintuitive? Like how does an infinite loop terminate? There's a lot of magic going on. I like approach #1 the best. Sure, there are some bugs, but a state diagram would help make it clearer instead of introducing magic.
Its not that unintuitive once you understand async/await and how the tasks are resumed. Execution is yielded at an await. At that time the loop is not running anywhere, its not even in a sleep state. The loop "terminates" by never being resumed.
Three ways of handling user input
11–17 of 17 posts
Re: Three ways of handling user input
#12Earlier quoted context omitted.
Its not that unintuitive once you understand async/await and how the tasks are resumed. Execution is yielded at an await. At that time the loop is not running anywhere, its not even in a sleep state. The loop "terminates" by never being resumed.
Wouldn't that result in a thread leak? (Or a "fiber" leak)
Re: Three ways of handling user input
#13Earlier quoted context omitted.
Its not that unintuitive once you understand async/await and how the tasks are resumed. Execution is yielded at an await. At that time the loop is not running anywhere, its not even in a sleep state. The loop "terminates" by never being resumed.
I'm assuming the loop would terminate with an exception... like `await events.pointermove` would raise some cancellation exception that would be silently captured.
Re: Three ways of handling user input
#14Earlier quoted context omitted.
Its not that unintuitive once you understand async/await and how the tasks are resumed. Execution is yielded at an await. At that time the loop is not running anywhere, its not even in a sleep state. The loop "terminates" by never being resumed.
Yeah that's still not the way the code reads. The closer the code behaves to the way it reads the better in my book.
Re: Three ways of handling user input
#15Earlier quoted context omitted.
I'm assuming the loop would terminate with an exception... like `await events.pointermove` would raise some cancellation exception that would be silently captured.
Sounds like the Abro runtime never resumes the tasks so how could they throw?
Re: Three ways of handling user input
#16Earlier quoted context omitted.
Sounds like the Abro runtime never resumes the tasks so how could they throw?
Oh... on second thought I realize the exception would have to come from `event.pointermove` (for example), and that object doesn't know anything about the receiver or whether it should cancel. So yeah, this does seem problematic.
Re: Three ways of handling user input
#17Earlier quoted context omitted.
I'm assuming the loop would terminate with an exception... like `await events.pointermove` would raise some cancellation exception that would be silently captured.
Sounds like the Abro runtime never resumes the tasks so how could they throw?
await Promise.any(fibers.map((f) => f.run()));
fibers.forEach((f) => f.terminate());
Abro will reject the promise of these `await event.xxx` https://github.com/pdubroy/handling-user-input/blob/main/abr... this._promises.forEach(({ reject }) => reject());
Which will throw an Exception and exit the 2 other functions.