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

Fix calling completion closure twice #323

Closed
wants to merge 1 commit into from

Conversation

ejensen
Copy link
Contributor

@ejensen ejensen commented Dec 3, 2020

Prevents calling completion closures multiple times by making the synchronous Client Result handling methods return their values rather than having completion parameters.

The changed method signatures are private so the change is non-breaking.

@@ -458,13 +452,10 @@ open class Client {
"""
ContentfulLogger.log(.error, message: errorMessage)
// In this case, .success means that a RateLimitError was successfully initialized.
completion(Result.success(rateLimitError))
return .success(rateLimitError)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an example where the return was missing, so the execution would continue after calling completion and would result in completion being called multiple times.

@@ -473,7 +464,7 @@ open class Client {
} catch let error {
let sdkError = SDKError.unparseableJSON(data: data, errorMessage: "\(error)")
ContentfulLogger.log(.error, message: sdkError.message)
completion(.failure(sdkError))
return .failure(sdkError)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another example of where function execution would continue after calling completion, resulting in completion being called twice.

…Client result handling methods return their results
@mariuskatcontentful
Copy link
Collaborator

Your branch was out of date so merged separately: #412

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