Skip to content

Commit

Permalink
refact longpolling
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Jul 31, 2024
1 parent 7855737 commit abf6bad
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions Sources/SwiftTelegramSdk/Bot/TGConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,16 @@ public final class TGLongPollingConnection: TGConnectionPrtcl {
let deleteWebHookParams: TGDeleteWebhookParams = .init(dropPendingUpdates: false)
try await bot.deleteWebhook(params: deleteWebHookParams)
Task.detached { [weak self] in
guard let self = self else { return }
var cancell: Bool = false
while !Task.isCancelled && !cancell {
try await Task.sleep(nanoseconds: 1_000_000_000)
while !Task.isCancelled {
guard let self = self else { break }
do {
try await Task.sleep(nanoseconds: 1_000_000_000)
let updates: [TGUpdate] = try await self.getUpdates(bot: bot)
bot.dispatcher.process(updates)
} catch {
self.log.error("\(BotError(error).localizedDescription)")
cancell = true
}
}
try await start(bot: bot)
}

return true
Expand Down

0 comments on commit abf6bad

Please sign in to comment.