Thomvis/BrightFutures

'continueWithBlock' method

Closed this issue · 2 comments

Is there a way to chain two futures without requiring the first future to either fail or succeed?
much like continueWithBlock method on BFTasks?

No, there is way to chain futures regardless of their success/failure. I'm not sure if there is a big use case for that. With BFTasks, I often ended up writing an if statement in the continueWithBlock to check for the error. I assume that most cases can be handled more elegantly with a combination of recover/recoverWith and map/flatMap. But if you think this is not the case, I'd like to see an example!

Yeah, I too realized there's probably few use case for it.
My own was, I wanted to make sure the dismissal of a view controller, which is called upon the completion of a future, is finished before I can do something with the result of the said future.
I just added an extension on AsyncType to help me with it:

extension AsyncType {
    func continueWith<AnotherAsync: AsyncType>(f: (Value) -> AnotherAsync) -> AnotherAsync {
        return AnotherAsync { complete in
            onComplete(ImmediateExecutionContext) { (result) in
                f(result).onComplete(ImmediateExecutionContext, callback: { (finalResult) in
                    complete(finalResult)
                })
            }
        }
    }
}