ScriptAsyncUtil

class ScriptAsyncUtil(jsPromiseConstructor: Value)

Async utils including game-based tick scheduling and network requests. JavaScript-only.

Author

MukjepScarlet

Constructors

Link copied to clipboard
constructor(jsPromiseConstructor: Value)

Types

Link copied to clipboard

Functions

Link copied to clipboard
fun conditional(ticks: Int, breakLoop: BooleanSupplier): Value

Example: const result = await conditional(20, () => mc.player.isOnGround())

Link copied to clipboard
fun <T> launch(block: Supplier<T>): Value

Starts an async task on Util.getMainWorkerExecutor(), returns a Promise. JS Promise result will be resolved or rejected on Render thread. You can use utils from java.util.concurrent to control your tasks.

fun <T> launch(executor: Executor, block: Supplier<T>): Value

Starts an async task on executor, returns a Promise. JS Promise result will be resolved or rejected on Render thread. You can use utils from java.util.concurrent to control your tasks.

Link copied to clipboard
fun request(block: Consumer<Request.Builder>): Value

Sends an HTTP request or websocket request asynchronously. (based on okhttp3) JS Promise result will be resolved or rejected on Render thread.

Link copied to clipboard
fun ticks(n: Int): Value

Example: await ticks(10)

Link copied to clipboard
@JvmName(name = "completableFutureToPromise")
fun <T> CompletableFuture<T>.toPromise(): Value

Converts a CompletableFuture to a JavaScript Value that represents a Promise.

Link copied to clipboard
fun until(condition: BooleanSupplier): Value

Example: const duration = await until(() => mc.player.isOnGround())