Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.1 KiB
49 lines
1.1 KiB
package org.openrs2.net
|
|
|
|
import io.netty.util.concurrent.Future
|
|
import java.util.concurrent.CompletableFuture
|
|
import kotlin.coroutines.resume
|
|
import kotlin.coroutines.resumeWithException
|
|
import kotlin.coroutines.suspendCoroutine
|
|
|
|
public suspend fun <V> Future<V>.awaitSuspend(): V {
|
|
if (isDone) {
|
|
if (isSuccess) {
|
|
return now
|
|
} else {
|
|
throw cause()
|
|
}
|
|
}
|
|
|
|
return suspendCoroutine { continuation ->
|
|
addListener {
|
|
if (isSuccess) {
|
|
continuation.resume(now)
|
|
} else {
|
|
continuation.resumeWithException(cause())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public fun <V> Future<V>.asCompletableFuture(): CompletableFuture<V> {
|
|
if (isDone) {
|
|
return if (isSuccess) {
|
|
CompletableFuture.completedFuture(now)
|
|
} else {
|
|
CompletableFuture.failedFuture(cause())
|
|
}
|
|
}
|
|
|
|
val future = CompletableFuture<V>()
|
|
|
|
addListener {
|
|
if (isSuccess) {
|
|
future.complete(now)
|
|
} else {
|
|
future.completeExceptionally(cause())
|
|
}
|
|
}
|
|
|
|
return future
|
|
}
|
|
|