Commit 422d84d1 authored by Him188's avatar Him188

Fix build

parent 1deb7958
...@@ -31,7 +31,7 @@ actual abstract class BotJavaHappyAPI actual constructor() { ...@@ -31,7 +31,7 @@ actual abstract class BotJavaHappyAPI actual constructor() {
} }
private inline fun <R> future(crossinline block: suspend Bot.() -> R): Future<R> { private inline fun <R> future(crossinline block: suspend Bot.() -> R): Future<R> {
return (this as Bot).run { future(block) } return (this as Bot).run { future { block() } }
} }
/** /**
...@@ -126,7 +126,6 @@ actual abstract class BotJavaHappyAPI actual constructor() { ...@@ -126,7 +126,6 @@ actual abstract class BotJavaHappyAPI actual constructor() {
* @param message 若需要验证请求时的验证消息. * @param message 若需要验证请求时的验证消息.
* @param remark 好友备注 * @param remark 好友备注
*/ */
@JvmOverloads
@JvmName("addFriend") @JvmName("addFriend")
fun __addFriendBlockingForJava__( fun __addFriendBlockingForJava__(
id: Long, id: Long,
...@@ -170,25 +169,18 @@ actual abstract class BotJavaHappyAPI actual constructor() { ...@@ -170,25 +169,18 @@ actual abstract class BotJavaHappyAPI actual constructor() {
} }
} }
private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Future<R> { // !!! 不要 crossinline, 会编译失败
return object : Future<R> { @UseExperimental(ExperimentalCoroutinesApi::class)
private fun <R> Bot.future(block: suspend Bot.() -> R): Future<R> {
val future = object : Future<R> {
val value: CompletableDeferred<R> = CompletableDeferred() val value: CompletableDeferred<R> = CompletableDeferred()
init {
launch {
@UseExperimental(ExperimentalCoroutinesApi::class)
value.completeWith(kotlin.runCatching { block() })
}
}
override fun isDone(): Boolean { override fun isDone(): Boolean {
return value.isCompleted return value.isCompleted
} }
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
override fun get(): R { override fun get(): R {
if (value.isCompleted) { if (value.isCompleted) {
@UseExperimental(ExperimentalCoroutinesApi::class)
return value.getCompleted() return value.getCompleted()
} }
return runBlocking { value.await() } return runBlocking { value.await() }
...@@ -196,7 +188,6 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur ...@@ -196,7 +188,6 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
override fun get(timeout: Long, unit: TimeUnit): R { override fun get(timeout: Long, unit: TimeUnit): R {
if (value.isCompleted) { if (value.isCompleted) {
@UseExperimental(ExperimentalCoroutinesApi::class)
return value.getCompleted() return value.getCompleted()
} }
return runBlocking { return runBlocking {
...@@ -222,4 +213,11 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur ...@@ -222,4 +213,11 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
return value.isCancelled return value.isCancelled
} }
} }
launch {
@UseExperimental(ExperimentalCoroutinesApi::class)
future.value.completeWith(kotlin.runCatching { block() })
}
return future
} }
\ No newline at end of file
...@@ -31,7 +31,7 @@ actual abstract class BotJavaHappyAPI actual constructor() { ...@@ -31,7 +31,7 @@ actual abstract class BotJavaHappyAPI actual constructor() {
} }
private inline fun <R> future(crossinline block: suspend Bot.() -> R): Future<R> { private inline fun <R> future(crossinline block: suspend Bot.() -> R): Future<R> {
return (this as Bot).run { future(block) } return (this as Bot).run { future { block() } }
} }
/** /**
...@@ -126,7 +126,6 @@ actual abstract class BotJavaHappyAPI actual constructor() { ...@@ -126,7 +126,6 @@ actual abstract class BotJavaHappyAPI actual constructor() {
* @param message 若需要验证请求时的验证消息. * @param message 若需要验证请求时的验证消息.
* @param remark 好友备注 * @param remark 好友备注
*/ */
@JvmOverloads
@JvmName("addFriend") @JvmName("addFriend")
fun __addFriendBlockingForJava__( fun __addFriendBlockingForJava__(
id: Long, id: Long,
...@@ -170,25 +169,17 @@ actual abstract class BotJavaHappyAPI actual constructor() { ...@@ -170,25 +169,17 @@ actual abstract class BotJavaHappyAPI actual constructor() {
} }
} }
private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Future<R> { @UseExperimental(ExperimentalCoroutinesApi::class)
return object : Future<R> { private fun <R> Bot.future(block: suspend Bot.() -> R): Future<R> {
val future = object : Future<R> {
val value: CompletableDeferred<R> = CompletableDeferred() val value: CompletableDeferred<R> = CompletableDeferred()
init {
launch {
@UseExperimental(ExperimentalCoroutinesApi::class)
value.completeWith(kotlin.runCatching { block() })
}
}
override fun isDone(): Boolean { override fun isDone(): Boolean {
return value.isCompleted return value.isCompleted
} }
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
override fun get(): R { override fun get(): R {
if (value.isCompleted) { if (value.isCompleted) {
@UseExperimental(ExperimentalCoroutinesApi::class)
return value.getCompleted() return value.getCompleted()
} }
return runBlocking { value.await() } return runBlocking { value.await() }
...@@ -196,7 +187,6 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur ...@@ -196,7 +187,6 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
override fun get(timeout: Long, unit: TimeUnit): R { override fun get(timeout: Long, unit: TimeUnit): R {
if (value.isCompleted) { if (value.isCompleted) {
@UseExperimental(ExperimentalCoroutinesApi::class)
return value.getCompleted() return value.getCompleted()
} }
return runBlocking { return runBlocking {
...@@ -222,4 +212,11 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur ...@@ -222,4 +212,11 @@ private inline fun <R> Bot.future(crossinline block: suspend Bot.() -> R): Futur
return value.isCancelled return value.isCancelled
} }
} }
launch {
@UseExperimental(ExperimentalCoroutinesApi::class)
future.value.completeWith(kotlin.runCatching { block() })
}
return future
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment