Thomvis / BrightFutures

Write great asynchronous code in Swift using futures and promises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash when listening to a sequence of the same Future objects

reidmain opened this issue · comments

In our app we have a method that makes a network request and returns a Future. If that method is called before the Future is fulfilled the same future object gets returned instead of making another network request and creating another Future.

When I was writing a test to ensure that if you called this method multiple times only a single network request was made I would constantly get a crash in Async.onComplete((() -> ()) -> (), callback : (A) -> ()) -> Self at /Users/reid/app/Carthage/Checkouts/BrightFutures/Sources/BrightFutures/Async.swift:123

After some poking around I was able to replicate the problem with the following block of code:

let promise = Promise<Bool, NoError>()
let future = promise.future

let futures = [future, future, future]

DispatchQueue.global().asyncAfter(deadline: DispatchTime.now() + 1) {
    promise.success(true)
}

futures.sequence().onComplete { _ in
}

This crashes every time on Xcode 8.3.3 against iOS 10.3.

Something interesting to mention is that if you remove the delay and only use DispatchTime.now() then this code executes perfectly.

I am using v5.2.0 of BrightFutures.

Sorry for the late reply, I was away travelling. I can reproduce the crash and will look into it soon. If you have made any progress yourself in the meantime, please let me know. Thanks!

No worries @Thomvis. I know maintaining an open source project is tough.

I unfortunately have not had any opportunity to dig into this deeper. I was attempting to port some code from Bolts to BrightFutures but then got switched over to another project. If I get the opportunity to circle back around to this I'll update the issue with my findings.