Re:Using Lua coroutines to create an RPG dialogue system
by anonymoushn on Tuesday January 10, 2017 @10:08PM
(#13371430)
The async/await model and the coroutine model are equally capable of expressing "start these 3 tasks and wake me up when they're all done." I've written this before in Python using Greenlet.
[ Parent
| on HN ]
Re:Using Lua coroutines to create an RPG dialogue system
by SomeCallMeTim on Wednesday January 11, 2017 @03:13PM
(#13377116)
Lua coroutines don't have that ability out of the box.
JavaScript promises do (Promise.all).
Re:Using Lua coroutines to create an RPG dialogue system
by anonymoushn on Wednesday January 11, 2017 @06:02PM
(#13378269)
This is an interesting characterization of the situation! I can save the 20 LOC involved in implementing this if I just give up the ability to write my own event loops and pepper my code with a bunch of additional "await"s every time I add an asynchronous operation to a function used by other functions.
Re:Using Lua coroutines to create an RPG dialogue system
by unscaled on Thursday January 12, 2017 @04:31AM
(#13380985)
You can also implement your own event loops with promises, but it's a matter of tradeoffs again:
You can't control the way functions written by someone else will schedule their internal continuations - you can only control the way you schedule your own continuation. I'm not sure if Javascript gives you a lot of control there, but C# allows you to define your own TaskScheduler and specify it on ContinueWith.