Implementing a wait function #71

Closed
opened 2020-06-23 17:33:22 +00:00 by orange451 · 5 comments
orange451 commented 2020-06-23 17:33:22 +00:00 (Migrated from github.com)

Hello! In my current project I implemented a very crude wait() method, where I literally just sleep the current thread for a desired length of time. This isn't very scalable, because if I have multiple lua scripts running, this becomes blocking and sleeps all scripts.

In my current project I run each script via a thread pool, but this doesn't seem like a good long-term solution. Since there can be hundreds of scripts in the project at any given time, I would rather not put them all on their own java thread.

I was wondering if there was a nicer way to implement wait(), such that it blocks only the current closure, but not additional scripts running in the application, or the current thread.

Hello! In my current project I implemented a very crude wait() method, where I literally just sleep the current thread for a desired length of time. This isn't very scalable, because if I have multiple lua scripts running, this becomes blocking and sleeps all scripts. In my current project I run each script via a thread pool, but this doesn't seem like a good long-term solution. Since there can be hundreds of scripts in the project at any given time, I would rather not put them all on their own java thread. I was wondering if there was a nicer way to implement wait(), such that it blocks only the current closure, but not additional scripts running in the application, or the current thread.
orange451 commented 2020-08-14 17:19:40 +00:00 (Migrated from github.com)

Still seeking a nice way to solve this issue! If anyone has any information I would love to hear your ideas!

Still seeking a nice way to solve this issue! If anyone has any information I would love to hear your ideas!
jplwill commented 2020-08-14 17:22:11 +00:00 (Migrated from github.com)

Maybe a coroutine plus a Java timeout that will wake the coroutine up? (Dunno, not an expert.)

Maybe a coroutine plus a Java timeout that will wake the coroutine up? (Dunno, not an expert.)
orange451 commented 2020-08-14 17:22:59 +00:00 (Migrated from github.com)

If I recall correctly, a coroutine in this library creates a LuaThread class, which creates a native java-Thread. I may be mistaken. I'll look a little more into this.

If I recall correctly, a coroutine in this library creates a LuaThread class, which creates a native java-Thread. I may be mistaken. I'll look a little more into this.
upsala commented 2021-01-07 14:31:52 +00:00 (Migrated from github.com)

Maybe it would be better to implements Event-Handling like in JavaScript.

Maybe it would be better to implements Event-Handling like in JavaScript.

Implemented

Implemented
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-autonomous-connection/luaj#71