-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: make polling to par with android #211
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a5bd4ca
feat: make polling to par with android
JNdhlovu b0e1550
Merge branch 'main' into feature/pollingtimeoutfix
JNdhlovu c0b6d3f
fix: lint
JNdhlovu f2140d9
fix: lint
JNdhlovu 2599463
fix: lint
JNdhlovu 989a86d
fix: ci arkana step
JNdhlovu 4089933
chore: ci fix
JNdhlovu 0900a29
chore: ci fix
JNdhlovu 9d715f8
feat: remove sentry from this branch
JNdhlovu 6077e32
feat: remove sentry fixes
JNdhlovu dc98712
chore: update changelog
JNdhlovu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ archives | |
*.mobileprovision | ||
*.sentryclirc | ||
.sentryclirc | ||
**/ArkanaKeys/ | ||
|
||
# JetBrains/AppCode | ||
.idea | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
global_secrets: | ||
- SENTRY_DSN | ||
package_manager: cocoapods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,35 +97,33 @@ public extension SmileIDServiceable { | |
/// - numAttempts: The maximum number of polls before ending the flow | ||
func pollJobStatus<T: JobResult>( | ||
request: JobStatusRequest, | ||
interval _: TimeInterval, | ||
interval: TimeInterval, | ||
numAttempts: Int | ||
) async throws -> JobStatusResponse<T> { | ||
var lastError: Error? | ||
var attemptCount = 0 | ||
|
||
func makeRequest() async throws -> JobStatusResponse<T> { | ||
attemptCount += 1 | ||
|
||
do { | ||
let response: JobStatusResponse<T> = try await SmileID.api.getJobStatus(request: request) | ||
if response.jobComplete { | ||
return response | ||
} else if attemptCount < numAttempts { | ||
return try await makeRequest() | ||
} else { | ||
throw SmileIDError.jobStatusTimeOut | ||
) -> AsyncThrowingStream<JobStatusResponse<T>, Error> { | ||
AsyncThrowingStream { continuation in | ||
Task { | ||
var latestError: Error? | ||
for _ in 0..<numAttempts { | ||
do { | ||
let response: JobStatusResponse<T> = try await SmileID.api.getJobStatus(request: request) | ||
continuation.yield(response) | ||
// Reset the error if the API response was successful | ||
latestError = nil | ||
if response.jobComplete { | ||
break | ||
} | ||
} catch { | ||
latestError = error | ||
} | ||
try await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please explain why you're introducing this delay? I think this can slow down the code execution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already discussed this during our sync. |
||
} | ||
} catch { | ||
lastError = error | ||
if attemptCount < numAttempts { | ||
return try await makeRequest() | ||
if let latestError = latestError { | ||
continuation.finish(throwing: latestError) | ||
} else { | ||
throw lastError ?? error | ||
continuation.finish() | ||
} | ||
} | ||
} | ||
|
||
return try await makeRequest() | ||
} | ||
|
||
/// Polls the server for the status of a SmartSelfie Job until it is complete. This should be called after | ||
|
@@ -141,8 +139,8 @@ public extension SmileIDServiceable { | |
request: JobStatusRequest, | ||
interval: TimeInterval, | ||
numAttempts: Int | ||
) async throws -> SmartSelfieJobStatusResponse { | ||
try await pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
) async throws -> AsyncThrowingStream<SmartSelfieJobStatusResponse, Error> { | ||
return pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
} | ||
|
||
/// Polls the server for the status of a Document Verification Job until it is complete. This should be called after | ||
|
@@ -158,8 +156,8 @@ public extension SmileIDServiceable { | |
request: JobStatusRequest, | ||
interval: TimeInterval, | ||
numAttempts: Int | ||
) async throws -> DocumentVerificationJobStatusResponse { | ||
try await pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
) async throws -> AsyncThrowingStream<DocumentVerificationJobStatusResponse, Error> { | ||
return pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
} | ||
|
||
/// Polls the server for the status of a Biometric KYC Job until it is complete. This should be called after | ||
|
@@ -175,8 +173,8 @@ public extension SmileIDServiceable { | |
request: JobStatusRequest, | ||
interval: TimeInterval, | ||
numAttempts: Int | ||
) async throws -> BiometricKycJobStatusResponse { | ||
try await pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
) async throws -> AsyncThrowingStream<BiometricKycJobStatusResponse, Error> { | ||
return pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
} | ||
|
||
/// Polls the server for the status of a Enhanced Document Verification Job until it is complete. | ||
|
@@ -193,8 +191,8 @@ public extension SmileIDServiceable { | |
request: JobStatusRequest, | ||
interval: TimeInterval, | ||
numAttempts: Int | ||
) async throws -> EnhancedDocumentVerificationJobStatusResponse { | ||
try await pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
) async throws -> AsyncThrowingStream<EnhancedDocumentVerificationJobStatusResponse, Error> { | ||
return pollJobStatus(request: request, interval: interval, numAttempts: numAttempts) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
redundant_optional_initialization
)