Skip to content

Commit

Permalink
add Sendable
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Mar 20, 2023
1 parent 78a4b42 commit df222ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions Sources/EverscaleClientSwift/Binding/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ public final class TSDKBindingModule: TSDKBindingPrtcl {

public func requestLibraryAsync(_ methodName: String,
_ payload: Encodable = "",
_ requestHandler: @escaping (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void
_ requestHandler: @escaping @Sendable (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void
) throws {
try convertToTSDKString(methodName) { tsdkMethodName in
let payload = payload.toJson() ?? ""
Expand Down Expand Up @@ -138,10 +138,10 @@ public final class TSDKBindingModule: TSDKBindingPrtcl {

public func requestLibraryAsyncAwait(_ methodName: String,
_ payload: Encodable = "",
_ requestHandler: @escaping (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void
_ requestHandler: @escaping @Sendable (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void
) throws {
try convertToTSDKString(methodName) { tsdkMethodName in
let payload = payload.toJson() ?? ""
Expand Down Expand Up @@ -172,7 +172,7 @@ public final class TSDKBindingModule: TSDKBindingPrtcl {
let response: BindingStore.RawResponse = try BindingStore.getCompleteResponse(requestId)
try responseHandler?(response.requestId, response.stringResponse, response.responseType, response.finished)
BindingStore.deleteCompleteResponse(requestId)
}
}
} catch {
BindingStore.deleteResponseHandler(requestId)
BindingStore.deleteCompleteResponse(requestId)
Expand Down
20 changes: 10 additions & 10 deletions Sources/EverscaleClientSwift/Binding/BindingStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import Foundation

public final class BindingStore {

private static var requsetId: UInt32 = .init()
private static let requestLock: NSLock = .init()
private static let asyncResponseLock: NSLock = .init()
public static var responses: [UInt32: (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void] = .init()

/// BECAUSE SDK METHODS LIKE PROCESS MESSAGE RETURNED TWO RESPONSE
/// FIRST REAL RESPONSE AND LAST EMPTY STRING WITH STATUS FINISHED
public typealias RawResponse = (requestId: UInt32,
Expand Down Expand Up @@ -44,18 +44,18 @@ public final class BindingStore {
defer { completeResponsesLock.unlock() }
completeResponses[id] = nil
}

public class func addResponseHandler(_ requestId: UInt32,
_ response: @escaping (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void
_ response: @escaping @Sendable (_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
_ finished: Bool) throws -> Void
) {
asyncResponseLock.lock()
responses[requestId] = response
asyncResponseLock.unlock()
}

public class func getResponseHandler(_ requestId: UInt32) -> ((_ requestId: UInt32,
_ stringResponse: String,
_ responseType: TSDKBindingResponseType,
Expand All @@ -64,13 +64,13 @@ public final class BindingStore {
defer { asyncResponseLock.unlock() }
return responses[requestId]
}

public class func deleteResponseHandler(_ requestId: UInt32) {
asyncResponseLock.lock()
defer { asyncResponseLock.unlock() }
responses[requestId] = nil
}

public class func generate_request_id() -> UInt32 {
requestLock.lock()
defer { requestLock.unlock() }
Expand Down

0 comments on commit df222ee

Please sign in to comment.