-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWIFT TASK CONTINUATION MISUSE: tried to resume its continuation more than once, returning nil! #3650
Comments
Didn't you use that I think this is indeed for that advanced control |
@dreampiggy Ohh I didn't aware of that context, how can I use it correctly? Thank you in advance. |
@dreampiggy I set |
Using un-attached Task with main actor and wrap that Swift Actor and async is actually, different concept. They should not just hack to match the exists Objc API like your wrapper. A proper solution is to wait my #2980 Or you can do a wrapper by direclly use API in |
It is not only with sd_setImage that this problem occurs. @discardableResult
func loadImage(url: URL,
options: SDWebImageOptions,
context: [SDWebImageContextOption: Any]?) async throws -> UIImage {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { [url, options, context] continuation in
guard Task.isCancelled == false else {
continuation.resume(throwing: CancellationError())
return
}
var context: [SDWebImageContextOption: Any] = context ?? [:]
// Select queue for work
let queue = SDCallbackQueue.main // .current also has trouble
queue.policy = .safeExecute // also tried without this
context[SDWebImageContextOption.callbackQueue] = queue
manager.loadImage(with: url,
options: options,
context: context,
progress: nil) { [continuation] image, _, error, _, _, _ in
// Cancelled
guard Task.isCancelled == false else {
continuation.resume(throwing: CancellationError())
return
}
// Error thrown
guard let image = image else {
// MISSUSE continuation here :)
continuation.resume(throwing: ImageLoaderError.imageLoadFailed.error(underlyingError: error, info: ["url": url]))
return
}
// Result exist
continuation.resume(returning: image)
}
}
} |
The bug exists because this API ( So, actually , pay attention:
This is why this can not be simple to wrap into a async function |
New Issue Checklist
Issue Info
Issue Description and Steps
When I wrap the sd_setImage in Swift Concurrency context, the crash happens, usually the first time I load and scroll the pretty large image list
Crash log:
The crash happens after I update SDWebImage from
5.9.1
to5.14.0
(to use lazyDecoding config). I tried to use the latest version (5.18.7) but it still happens.The text was updated successfully, but these errors were encountered: