-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ✨ 为ConnectFactory 添加统一的Producer API * feat: ✨ 替换OverFlowImpl.start0里的过期api * feat: ✨ 1 * do not log anything if printInfo is false * Update Overflow.kt --------- Co-authored-by: 人間工作 <coolxiaom95@gmail.com>
- Loading branch information
Showing
11 changed files
with
473 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
onebot/src/main/kotlin/client/connection/platform-connection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cn.evolvefield.onebot.client.connection | ||
|
||
import cn.evolvefield.onebot.client.core.Bot | ||
import kotlinx.coroutines.withTimeout | ||
import kotlin.time.Duration | ||
|
||
interface OneBotProducer { | ||
fun invokeOnClose(block: () -> Unit) | ||
fun close() | ||
suspend fun awaitNewBotConnection(duration: Duration = Duration.INFINITE): Bot? | ||
} | ||
|
||
class PositiveOneBotProducer(private val client: WSClient) : OneBotProducer { | ||
override fun invokeOnClose(block: () -> Unit) = TODO("客户端暂不支持断线重连") | ||
|
||
override fun close() = client.close() | ||
|
||
override suspend fun awaitNewBotConnection(duration: Duration): Bot? { | ||
return kotlin.runCatching { | ||
withTimeout(duration) { | ||
if (client.connectSuspend()) client.createBot() else null | ||
} | ||
}.getOrNull() | ||
} | ||
} | ||
|
||
class ReversedOneBotProducer(private val server: WSServer) : OneBotProducer { | ||
override fun invokeOnClose(block: () -> Unit) { | ||
server.closeHandler.add(block) | ||
} | ||
|
||
override fun close() = server.stop() | ||
|
||
override suspend fun awaitNewBotConnection(duration: Duration): Bot? { | ||
return kotlin.runCatching { | ||
withTimeout(duration) { | ||
server.awaitNewBot() | ||
} | ||
}.getOrNull() | ||
} | ||
} |
Oops, something went wrong.