SkriptLang / skript-reflect

Powerful reflection utilities for Skript.
MIT License
56 stars 19 forks source link

Async reflection can be delayed #34

Closed TPGamesNL closed 3 years ago

TPGamesNL commented 3 years ago

Because of https://github.com/TPGamesNL/skript-reflect/blob/2.x/src/main/java/com/btk5h/skriptmirror/skript/EffExpressionStatement.java#L27 the maximum number of simultaneously running reflection calls is limited by the return value of above method. Example:

import:
    java.lang.Thread
    java.lang.Runnable
    java.lang.System
    java.lang.Runtime

function test(proxy: object):
    await {_proxy}.run()

command /test:
    trigger:
        broadcast "availableProcessors: %Runtime.getRuntime().availableProcessors()%"
        set {_start} to now
        loop 5 times:
            set {_i} to loop-value
            create section stored in {_f::run}:
                broadcast "[%{_i}%] started @ %difference between {_start} and now%"
                Thread.sleep(1000)
            set {_proxy::%{_i}%} to proxy of Runnable from {_f::*}
        loop 5 times:
            test({_proxy::%loop-value%})

output:

availableProcessors: 4
[3] started @ 0.001 seconds
[1] started @ 0.001 seconds
[4] started @ 0.001 seconds
[2] started @ 0.002 seconds
[5] started @ 1.002 seconds