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

Add support for cancellable Promise in await operator #45

Closed
tcurdt opened this issue Aug 23, 2017 · 2 comments
Closed

Add support for cancellable Promise in await operator #45

tcurdt opened this issue Aug 23, 2017 · 2 comments
Assignees
Milestone

Comments

@tcurdt
Copy link

tcurdt commented Aug 23, 2017

Let's say I use the example:

let asyncFunc = async({ _ -> Int in
  let loggedUser = try await(loginUser(username,pass))
  let followersList = try await(getFollowers(loggedUser))
  let countUnfollowed = try await(unfollow(followersList))
  return countUnfollowed
}).then({ value in
  print("Unfollowed \(value) users")
})

How would I make that cancelable?

@malcommac malcommac changed the title await and cancel Added support for cancellable Promise in await operator Aug 29, 2017
@malcommac malcommac changed the title Added support for cancellable Promise in await operator Add support for cancellable Promise in await operator Aug 29, 2017
malcommac added a commit that referenced this issue Aug 29, 2017
Fix #45 : Added support for cancellable promise in async operator, including test.
@malcommac
Copy link
Owner

Thank you for your request; I've added it in 0.9.91.
Below a short example used in unit test.

	func test_invalidationTokenWithAsyncOperator() {
		let exp = expectation(description: "test_retry_condition")
		let invalidator: InvalidationToken = InvalidationToken()
		
		async(token: invalidator, { st -> String in
			Thread.sleep(forTimeInterval: 2.0)
			if st.isCancelled {
				print("Promise cancelled")
				exp.fulfill()
			} else {
				print("Promise resolved")
				XCTFail()
			}
			return ""
		}).then { _ in

		}
		invalidator.invalidate()
		waitForExpectations(timeout: expTimeout, handler: nil)
	}

@malcommac malcommac added this to the 0.9.91 milestone Aug 29, 2017
@malcommac malcommac self-assigned this Aug 29, 2017
@tcurdt
Copy link
Author

tcurdt commented Aug 29, 2017

@malcommac thanks for looking into this. TBH I don't fully grasp the usage and how to apply it to the above snipped though.

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

No branches or pull requests

2 participants