Package-level declarations

Types

Link copied to clipboard
abstract class AbstractKtxDispatcher : CoroutineDispatcher, KtxDispatcher

Base extension of CoroutineDispatcher for dispatchers using the libGDX threading model. Uses libGDX Timer API to support delay.

Link copied to clipboard
class AsyncExecutorDispatcher(val executor: AsyncExecutor, val threads: Int = -1) : AbstractKtxDispatcher, Closeable, Disposable

A CoroutineDispatcher that wraps around libGDX AsyncExecutor instance (available via executor property) to execute tasks asynchronously. threads property is purely informational and cannot be verified, since AsyncExecutor does not expose the amount of threads it uses internally; provide a valid threads amount during initiation or use the official factory methods to prevent from mismatches with the actual max threads amount.

Link copied to clipboard
class DisposableTimerTask(val task: Timer.Task) : DisposableHandle, Disposable

Wraps around libGDX Timer.Task to make it possible to cancel scheduled tasks. Holds a reference to the original scheduled task.

Link copied to clipboard
class HttpRequestResult(val url: String, val method: String, val statusCode: Int, val content: ByteArray, val headers: Map<String, List<String>>)

Stores result of a HttpRequest. A safer alternative to HttpResponse.

Link copied to clipboard
object KtxAsync : CoroutineScope

Main KTX coroutine scope. Executes tasks on the main rendering thread. See MainDispatcher.

Link copied to clipboard
interface KtxDispatcher : CoroutineContext, Delay

Base interface of CoroutineContext for dispatchers using the libGDX threading model. Uses libGDX Timer API to support delay.

Link copied to clipboard

Executes tasks on the main rendering thread. See RenderingThreadDispatcher.

Link copied to clipboard
sealed class RenderingThreadDispatcher : MainCoroutineDispatcher, KtxDispatcher, Delay

A CoroutineDispatcher that wraps around libGDX runnable execution API to execute tasks on the main rendering thread. Uses libGDX Timer API to support delay.

Link copied to clipboard
class RenderingThreadDispatcherFactory : MainDispatcherFactory

Implements MainDispatcherFactory to provide references to the MainDispatcher.

Properties

Link copied to clipboard
val Dispatchers.KTX: MainDispatcher

Main KTX coroutine dispatcher. Executes tasks on the main rendering thread. See MainDispatcher.

Functions

Link copied to clipboard
suspend fun httpRequest(url: String, method: String = "GET", headers: Map<String, String> = emptyMap(), timeout: Int = 0, content: String? = null, contentStream: Pair<InputStream, Long>? = null, followRedirects: Boolean = true, includeCredentials: Boolean = false, onCancel: (Net.HttpRequest) -> Unit? = null): HttpRequestResult

Executes a HTTP request asynchronously.

Link copied to clipboard
inline fun interval(intervalSeconds: Float, delaySeconds: Float = 0.0f, repeatCount: Int = -2, crossinline task: () -> Unit): Timer.Task

Simplifies Timer API.

Link copied to clipboard
fun CoroutineScope.isOnRenderingThread(): Boolean

Returns true if the coroutine was launched from a rendering thread dispatcher.

Link copied to clipboard
fun newAsyncContext(threads: Int, threadName: String = "AsyncExecutor-Thread"): AsyncExecutorDispatcher

Creates a new AsyncExecutorDispatcher wrapping around an AsyncExecutor with the chosen amount of threads to execute tasks asynchronously outside of the main rendering thread.

Link copied to clipboard
fun newSingleThreadAsyncContext(threadName: String = "AsyncExecutor-Thread"): AsyncExecutorDispatcher

Creates a new AsyncExecutorDispatcher wrapping around an AsyncExecutor with a single thread to execute tasks asynchronously outside of the main rendering thread.

Link copied to clipboard
suspend fun <T> onRenderingThread(block: suspend CoroutineScope.() -> T): T

Suspends the coroutine to execute the defined block on the main rendering thread and return its result.

Link copied to clipboard
fun RenderingScope(): CoroutineScope

Creates a coroutine scope in the rendering thread with a supervisor job. Allows to manage multiple tasks executed on the main rendering thread within a single scope, providing mass actions such as task cancelling that do not affect other scopes.

Link copied to clipboard
inline fun schedule(delaySeconds: Float, crossinline task: () -> Unit): Timer.Task

Simplifies Timer API.

Link copied to clipboard
suspend fun skipFrame()

Attempts to skip the current frame. Resumes the execution using a task scheduled with Application.postRunnable.

Link copied to clipboard
fun Net.HttpResponse.toHttpRequestResult(requestData: Net.HttpRequest): HttpRequestResult

Converts this non thread-safe HttpResponse to HttpRequestResult that reads and caches the HTTP result content as byte array. Note that this method blocks the current thread until the HTTP result content is read.