Skip to content

Commit

Permalink
SDKS-3458 - More improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jeyanthanperiyasamy committed Nov 4, 2024
1 parent be03b0b commit 477e831
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions PingOrchestrate/PingOrchestrate/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import Foundation
import PingLogger

/// `HttpClient` is responsible for handling HTTP requests and logging the details of those requests and responses.
public final class HttpClient {
var session: URLSession
public final class HttpClient: Sendable {
let session: URLSession

/// Initializes a new instance of `HttpClient`.
/// - Parameter session: The URLSession instance to be used for HTTP requests. Defaults to a session with `RedirectPreventer` delegate.
Expand Down
2 changes: 1 addition & 1 deletion PingOrchestrate/PingOrchestrate/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public protocol Closeable {
public protocol Node: Sendable {}

/// Represents an EmptyNode node in the workflow.
public struct EmptyNode: Node, @unchecked Sendable {
public struct EmptyNode: Node, Sendable {
public init() {}
}

Expand Down
2 changes: 1 addition & 1 deletion PingOrchestrate/PingOrchestrate/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
import UIKit

/// Class for a Request. A Request represents a request to be sent over the network.
public class Request {
public final class Request {

public private(set) var urlRequest: URLRequest = URLRequest(url: URL(string: "https://")!)

Expand Down
24 changes: 8 additions & 16 deletions PingOrchestrate/PingOrchestrate/SharedContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ import Foundation

/// An actor that manages a shared context using a dictionary.
public final class SharedContext {
private var map: [String: Any] = [:]
private var map: [String: Any]

private var queue = DispatchQueue(label: "shared.conext.queue", attributes: .concurrent)

/// Initializes the SharedContext with an empty dictionary or a pre-existing one.
///
/// - Parameter map: A dictionary to initialize the context with. Defaults to an empty dictionary.
public init(_ map: [String: Any] = [:]) {
queue.sync(flags: .barrier) {
self.map = map
}
self.map = map
}

/// Sets a value for the given key in the shared context.
Expand All @@ -31,36 +30,29 @@ public final class SharedContext {
/// - key: The key for which to set the value.
/// - value: The value to set for the given key.
public func set(key: String, value: Any) {
queue.sync(flags: .barrier) {
self.map[key] = value
}
self.map[key] = value
}

/// Retrieves the value for the given key from the shared context.
///
/// - Parameter key: The key for which to get the value.
/// - Returns: The value associated with the key, or `nil` if the key does not exist.
public func get(key: String) -> Any? {
queue.sync {
return self.map[key]
}
return self.map[key]

}

/// Removes the value for the given key from the shared context.
///
/// - Parameter key: The key for which to remove the value.
/// - Returns: The removed value, or `nil` if the key does not exist.
public func removeValue(forKey key: String) -> Any? {
queue.sync(flags: .barrier) {
self.map.removeValue(forKey: key)
}
self.map.removeValue(forKey: key)
}

/// A Boolean value indicating whether the shared context is empty.
public var isEmpty: Bool {
queue.sync {
return self.map.isEmpty
}
return self.map.isEmpty
}

/// A namespace for key names to be added in an extension.
Expand Down

0 comments on commit 477e831

Please sign in to comment.