This repository was archived by the owner on Aug 29, 2022. It is now read-only.

Description
Right now, there is a way to recover from an error and produce a new default value for the SuccessValue. I think a way to recover from an error by producing a new Task for the same SuccessValue would be helpful.
Do you think something like this would be helpful?
extension Task {
public func recover(upon executor: Executor, start startNextTask: @escaping(Error) -> Task<SuccessValue>) -> Task<SuccessValue> {
let future: Future<TaskResult<SuccessValue>> = andThen(upon: executor) { (result) -> Task<SuccessValue> in
do {
let value = try result.extract()
return Task<SuccessValue>(success: value)
} catch let error {
return startNextTask(error)
}
}
return Task<SuccessValue>(future: future)
}
}