I have a function that takes 2 callbacks. I want to convert this into async/await. But how can I await while continuously returning the progress also? I am using https://github.com/yannickl/AwaitKit to get rid of callbacks.
typealias GetResultCallBack = (String) -> Void
typealias ProgressCallBack = (Double) -> Void
func getFileFromS3(onComplete callBack: @escaping GetResultCallBack,
progress progressCallback: @escaping ProgressCallBack) {
}
I am using it like this:
getFileFromS3() { [weak self] (result) in
guard let self = self else { return }
// Do something with result
} progress: { [weak self] (progress) in
guard let self = self else { return }
DispatchQueue.main.async { [weak self] in
guard let self = self else {return}
// Update progress in UI
}
}
Here is what converted code looks without progress reporting:
func getFileFromS3() -> Promise<String> {
return async {
// return here
}
}