Closed Computermatronic closed 10 years ago
Welcome to the group of people that want preemptive scheduling on a system that's designed to do cooperative scheduling ;-)
OC only uses LuaJ as a fallback (so... almost never), and then we're talking hacking the C implementation, because here yielding from debug hooks is only possible from C hooks - and if that weren't bad enough, coroutines yielded that way cannot be persisted at this time, and probably won't be any time remotely soon. So that's a no-go for now.
If you just want a timeout on "untrusted" code, make use of OC's own timeout error - override coroutine.resume
in your sandbox to avoid the error being ignored, if you have to (rethrow it when it happens).
It would be nice if there was better control over coroutines. e.g. coroutine.resume(ms) So that a coroutines could be executed for a specific amount of time. Implementation would not be particularly complicate (I don't use scala I use java so I'm not 100% on scala implementation) because a while ago I wrote a simple patch for luaj that used a timing thread to call yield after x amount of time, but I assume there would be a better implementation