Fix async

This commit is contained in:
Kylmakalle 2025-07-13 00:14:15 +03:00
parent 3c5c0ead92
commit 028a7f38d0
3 changed files with 35 additions and 35 deletions

View File

@ -11,13 +11,13 @@ public func updateSGGHSettingsInteractivelly(context: AccountContext) {
let _ = Task {
do {
let settings = try await fetchSGGHSettings(locale: locale)
let _ = (context.account.postbox.transaction { transaction in
let _ = await (context.account.postbox.transaction { transaction in
updateAppConfiguration(transaction: transaction, { configuration -> AppConfiguration in
var configuration = configuration
configuration.sgGHSettings = settings
return configuration
})
}).task
}).task()
} catch {
return
}
@ -57,7 +57,7 @@ func fetchSGGHSettings(locale: String) async throws -> SGGHSettings {
continue
}
for attempt in 1...maxRetries {
attemptsOuter: for attempt in 1...maxRetries {
do {
let (data, response) = try await URLSession.shared.data(from: url)
guard let httpResponse = response as? HTTPURLResponse else {
@ -78,7 +78,8 @@ func fetchSGGHSettings(locale: String) async throws -> SGGHSettings {
throw SGGHFetchError.decodingFailed
}
case 404:
break // Try the next fallback
SGLogger.shared.log("SGGHSettings", "[\(attempt)] Not found \(candidate) on the remote.")
break attemptsOuter
default:
SGLogger.shared.log("SGGHSettings", "[\(attempt)] Fetch failed for \(candidate), status code: \(httpResponse.statusCode)")
throw SGGHFetchError.fetchFailed(statusCode: httpResponse.statusCode)

View File

@ -86,28 +86,26 @@ public extension Signal {
}
}
var task: () async throws -> T {
{
let disposable = MetaDisposable()
return try await withTaskCancellationHandler(operation: {
return try await withCheckedThrowingContinuation { continuation in
disposable.set((self |> take(1)).startStandalone(
next: { value in
continuation.resume(returning: value)
},
error: { err in
continuation.resume(throwing: SignalError(err))
}
))
}
}, onCancel: {
disposable.dispose()
})
}
func task() async throws -> T {
let disposable = MetaDisposable()
return try await withTaskCancellationHandler(operation: {
return try await withCheckedThrowingContinuation { continuation in
disposable.set((self |> take(1)).startStandalone(
next: { value in
continuation.resume(returning: value)
},
error: { err in
continuation.resume(throwing: SignalError(err))
}
))
}
}, onCancel: {
disposable.dispose()
})
}
var stream: AsyncThrowingStream<T, Error> {
AsyncThrowingStream { continuation in
func stream() -> AsyncThrowingStream<T, Error> {
return AsyncThrowingStream { continuation in
let disposable = self.startStandalone(
next: { value in
continuation.yield(value)
@ -127,14 +125,12 @@ public extension Signal {
}
public extension Signal where E == NoError {
var task: () async -> T {
{
await self.get()
}
func task() async -> T {
return await self.get()
}
var stream: AsyncStream<T> {
AsyncStream { continuation in
func stream() -> AsyncStream<T> {
return AsyncStream { continuation in
let disposable = self.startStandalone(
next: { value in
continuation.yield(value)

View File

@ -2012,7 +2012,10 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
SharedDisplayLinkDriver.shared.updateForegroundState(self.isActiveValue)
}
func runForegroundTasks(onlySG: Bool = false) {
func runForegroundTasks() {
var sgTasksLaunched: Bool = false
let _ = (self.sharedContextPromise.get()
|> take(1)
@ -2022,10 +2025,10 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
|> deliverOnMainQueue).start(next: { activeAccounts in
for (_, context, _) in activeAccounts.accounts {
// MARK: Swiftgram
updateSGWebSettingsInteractivelly(context: context)
updateSGGHSettingsInteractivelly(context: context)
if onlySG {
continue
if !sgTasksLaunched {
updateSGWebSettingsInteractivelly(context: context)
updateSGGHSettingsInteractivelly(context: context)
sgTasksLaunched = true
}
(context.downloadedMediaStoreManager as? DownloadedMediaStoreManagerImpl)?.runTasks()
}