News for hackers. Stuff that matters.
Re:Three ways of handling user input by jayd16 on Friday January 07, 2022 @02:49AM (#29836260)
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.
Re:Three ways of handling user input by xupybd on Friday January 07, 2022 @04:03AM (#29836809)
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 by jayd16 on Friday January 07, 2022 @12:59PM (#29842355)
How does it read to you?
Re:Three ways of handling user input by ianbicking on Friday January 07, 2022 @11:07AM (#29840754)
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 by jayd16 on Friday January 07, 2022 @12:57PM (#29842307)
Sounds like the Abro runtime never resumes the tasks so how could they throw?
Re:Three ways of handling user input by rexpan on Friday January 14, 2022 @01:01AM (#29931098)
These 3 functions will stop on `await event.xxx` (if not, they will continue to execute or terminate). So when one of the functions is terminate https://github.com/pdubroy/handling-user-input/blob/main/abr...

   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.
Re:Three ways of handling user input by ianbicking on Friday January 07, 2022 @01:01PM (#29842377)
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 by jayd16 on Friday January 07, 2022 @02:58PM (#29843939)
Are you worried about when the case when an exception should be thrown from the thing being awaited? I'm not familiar with Arbo but usually the promise holds on to the exception until its observed. It could be that Arbo is configured to ignore the exception if the task is already cancelled.
Re:Three ways of handling user input by bruce343434 on Friday January 07, 2022 @04:58AM (#29837242)
Wouldn't that result in a thread leak? (Or a "fiber" leak)
Re:Three ways of handling user input by jayd16 on Friday January 07, 2022 @12:54PM (#29842267)
If a task has yielded its not holding on to a thread. A loop that wasn't yielding would leak, though.