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

Include new async / await language feature to make parallel executions possible #6

Merged
merged 6 commits into from
Oct 2, 2022

Conversation

LubomirYordanov
Copy link
Contributor

No description provided.

Copy link
Owner

@KoCMoHaBTa KoCMoHaBTa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • All async protocol requirements should be converted to protocol extensions that calls the original function with a continucation in order to maintain backward compatibility.
  • Remove the Async suffix from all method names, because it is redundant with the async keyword.
  • All async functions should not return Optional value just because the completion handler return an Optional - that's because the completion handlers return either the result or an error. For async functions they should either throw an error or return non-optional result. The only exception from that case would be where the Optional value make sense and is valid result.
  • All async test functions that calls throwing code should be made throws, so there will be no need to force unwrap errors.

@@ -17,6 +17,9 @@ public protocol CredentialsProvider {
///Provides credentials in an asynchronous manner. Can be implemented in a way to show a login screen.
func credentials(handler: @escaping (Username, Password) -> Void)

@available(iOS 13, tvOS 13.0.0, macOS 10.15, *)
func credentialsAsync() async -> (Username, Password)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be a protocol requirement, but a protocol extension with the implementation.

Remove the Async suffix from the method name.

These should be applied to all similar cases.

@@ -61,6 +70,14 @@ extension IdentityManager {
handler?(error)
}
}

@available(iOS 13, tvOS 13.0.0, macOS 10.15, *)
public func forceAuthenticateAsync() async throws {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly call the respective forceAuthenticate using a continuation.

@@ -63,6 +63,23 @@ open class DefaultAccessTokenRefresher: AccessTokenRefresher {
}
}
}

@available(iOS 13, tvOS 13.0.0, macOS 10.15, *)
open func refreshAsync(using requestModel: AccessTokenRefreshRequest) async throws -> AccessTokenResponse? {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result should not be optional. It should throw an error (eg. MHIdentityKitError.Reason.invalidAccessTokenResponse) if there is no AccessTokenResponse.

This should be applied to all similar cases.


let manager = OAuth2IdentityManager(flow: Flow(e: XCTestExpectation(description: "XCTestCase Default Expectation")), refresher: Refresher(e: XCTestExpectation(description: "XCTestCase Default Expectation")), storage: InMemoryIdentityStorage(), authorizationMethod: .header)

let request1 = try! await manager.authorizeAsync(request: URLRequest(url: URL(string: "http://foo.bar")!), forceAuthenticate: false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the test function throwing, so there will be no need to force unwrap the error.

This should be applied to all similar cases.

…ix from all method names, async functions do not return optional value just because the handler does it, async test functions calling throwing code marked as throwing.
Copy link
Owner

@KoCMoHaBTa KoCMoHaBTa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add documentation to each new function.

@@ -11,73 +11,74 @@ import Foundation
import XCTest
@testable import MHIdentityKit

@available(iOS 13, tvOS 13.0.0, macOS 10.15, *)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should not be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to bring it back as it was before?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i have no idea why you changed that test.

@KoCMoHaBTa KoCMoHaBTa merged commit b00e7ea into KoCMoHaBTa:master Oct 2, 2022
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

Successfully merging this pull request may close these issues.

2 participants