Implement `requiresMainThread`
bluelhf opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
In its current state, the requiresMainThread
setting for expressions is never respected. In fact, the term "requiresMainThread" only occurs twice in the entirety of the ByteSkript source code: once in SyntaxElement.java
, where it is defined, and once in ExprSystemInput.java
, which is the only built-in expression to use the feature.
Describe the solution you'd like
The requiresMainThread
setting should cause not only the expression's compiled code but also its handlers to be wrapped using a mechanism that allows the code to run only on the main thread of execution.
Describe alternatives you've considered
Not applicable.
Additional context
Project maintainers are likely already aware of the lack of implementation for this feature. This issue is not a feature request per se, rather it is meant to express the demand for the feature along with sparking discussion regarding possible implementation details.
The idea of 'main thread' is ill-defined and not really applicable to the base language outside things like system input which requires being asked for from the console thread.
It's something that I expect offshoots to need (e.g. Bukkit things) but there's not a huge amount I can do to support it here since it's likely something that's very implementation-dependent.
After further consideration I believe that it may be best to leave synchronisation with the illusive "main thread" up to library maintainers: ByteSkript code cannot truly run on the main thread without some sort of task queue, which would block the main thread indefinitely. It is also not implicitly guaranteed that ByteSkript's main thread is actually the same as, or even synchronized with, the main thread of the library's host program (assuming the library maintainer does not make deliberate efforts to ensure this behaviour), so this feature may not be applicable even in the context of the aforementioned offshoots.
Pull request #9 addressed this issue, removing the requireMainThread
method completely. As of now, both the method definition and its one usage in the project are commented out.