|
|
@ -1,6 +1,7 @@ |
|
|
|
package org.openrs2.net |
|
|
|
package org.openrs2.net |
|
|
|
|
|
|
|
|
|
|
|
import io.netty.util.concurrent.Future |
|
|
|
import io.netty.util.concurrent.Future |
|
|
|
|
|
|
|
import java.util.concurrent.CompletableFuture |
|
|
|
import kotlin.coroutines.resume |
|
|
|
import kotlin.coroutines.resume |
|
|
|
import kotlin.coroutines.resumeWithException |
|
|
|
import kotlin.coroutines.resumeWithException |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
|
import kotlin.coroutines.suspendCoroutine |
|
|
@ -24,3 +25,25 @@ public suspend fun <V> Future<V>.awaitSuspend(): V { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|