Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancellable Promise in a Chain #64

Open
alextosatto opened this issue Nov 19, 2018 · 0 comments
Open

Cancellable Promise in a Chain #64

alextosatto opened this issue Nov 19, 2018 · 0 comments

Comments

@alextosatto
Copy link

Hi guys, I have been using this library for a while and I have to say it's very easy to work with it.

I have a concern about cancellable promises, specifically the behaviour of a chain of promises when a promise in the middle has been cancelled.
Let's say we have:

A.then(B).then(C).then(D).then(E)
    .then { _ in
        print("success")
    }.catch { _ in
        print("failed")
    }.cancelled { in
        print("cancelled")
    }

If, for example, C gets cancelled while A and B resolve correctly, I'm expecting that cancelled is printed out, but what I observe is that the sequence gets stuck in pending state.
This behaviour can be checked with the following test that recalls the ones provided with the library, which fails for timeout:

  func test_cancelledPromiseChainable2() {
    let exp = expectation(description: "test_cancelledPromiseChainable2")
    
    let invalidator: InvalidationToken = InvalidationToken()
    invalidator.isCancelled = true
    
    intPromise().then { _ in
        self.test_invalidationToken(token: invalidator)
      }.then { total in
        print("Operation finished with: \(total)")
        XCTFail()
      }.catch { _ in
        print("Operation failed")
      }.cancelled {
        print("Operation cancelled")
        exp.fulfill()
    }
    
    waitForExpectations(timeout: expTimeout, handler: nil)
  }

If I'm not misinterpreting the situation, I will open a PR with a suggested fix, otherwise please let me know the reasoning behind this behaviour.

Thanks,
AT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant