Skip to content

Commit

Permalink
Update interface names; Add comments about semaphore usage
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Nascimento <[email protected]>
  • Loading branch information
theosirian committed Sep 3, 2024
1 parent e7fb67d commit 41a2614
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/MobileSdk/OID4VCI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

import SpruceIDMobileSdkRs

public class Oid4vciSyncHttpClient : SpruceIDMobileSdkRs.HttpClient {
public class Oid4vciSyncHttpClient : SyncHttpClient {
public func httpClient(request: HttpRequest) throws -> HttpResponse {
guard let url = URL(string: request.url) else {
throw HttpClientError.Other(error: "failed to construct URL")
Expand All @@ -16,6 +16,7 @@ public class Oid4vciSyncHttpClient : SpruceIDMobileSdkRs.HttpClient {
req.httpBody = request.body
req.allHTTPHeaderFields = request.headers

// Semaphore used to wait for the callback to complete
let semaphore = DispatchSemaphore(value: 0)

var data: Data?
Expand All @@ -27,10 +28,14 @@ public class Oid4vciSyncHttpClient : SpruceIDMobileSdkRs.HttpClient {
response = $1
error = $2

// Signaling from inside the callback will let the outside function
// know that `data`, `response` and `error` are ready to be read.
semaphore.signal()
}
// Initiate execution of the http request
dataTask.resume()

// Blocking wait for the callback to signal back
_ = semaphore.wait(timeout: .distantFuture)

if let error {
Expand Down Expand Up @@ -68,7 +73,7 @@ public class Oid4vciSyncHttpClient : SpruceIDMobileSdkRs.HttpClient {
}
}

public class Oid4vciAsyncHttpClient : SpruceIDMobileSdkRs.AsyncHttpClient {
public class Oid4vciAsyncHttpClient : AsyncHttpClient {
public func httpClient(request: HttpRequest) async throws -> HttpResponse {
guard let url = URL(string: request.url) else {
throw HttpClientError.Other(error: "failed to construct URL")
Expand Down

0 comments on commit 41a2614

Please sign in to comment.