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

Recover and produce a new Task #149

@piercifani

Description

@piercifani

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)
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions