mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
Squash merge of 1,462 upstream commits with openclaw→hanzo-bot naming transforms applied. Conflicts resolved favoring our main branch to preserve existing customizations. Key upstream additions: - iOS Security Stack (concurrency locks, runtime guards, TTS fallback) - Discord CDN hostname allowlisting for SSRF protection - Discord mention handling improvements - Various bug fixes and stability improvements
35 lines
940 B
Swift
35 lines
940 B
Swift
import BotKit
|
|
|
|
enum GatewayPushSubscription {
|
|
@MainActor
|
|
static func consume(
|
|
bufferingNewest: Int? = nil,
|
|
onPush: @escaping @MainActor (GatewayPush) -> Void) async
|
|
{
|
|
let stream: AsyncStream<GatewayPush> = if let bufferingNewest {
|
|
await GatewayConnection.shared.subscribe(bufferingNewest: bufferingNewest)
|
|
} else {
|
|
await GatewayConnection.shared.subscribe()
|
|
}
|
|
|
|
for await push in stream {
|
|
if Task.isCancelled { return }
|
|
await MainActor.run {
|
|
onPush(push)
|
|
}
|
|
}
|
|
}
|
|
|
|
@MainActor
|
|
static func restartTask(
|
|
task: inout Task<Void, Never>?,
|
|
bufferingNewest: Int? = nil,
|
|
onPush: @escaping @MainActor (GatewayPush) -> Void)
|
|
{
|
|
task?.cancel()
|
|
task = Task {
|
|
await self.consume(bufferingNewest: bufferingNewest, onPush: onPush)
|
|
}
|
|
}
|
|
}
|