Skip to content

Commit

Permalink
[Fastlane.Swift] Swift fastlane does not run on Apple Silicon fastlan…
Browse files Browse the repository at this point in the history
…e#18502

* [Swift] Implement subscript as suggested by reviewers.
  • Loading branch information
kikeenrique committed Dec 4, 2021
1 parent d795f2e commit 214d2e2
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions fastlane/swift/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,32 @@ class AtomicDictionary<Key: Hashable, Value> {
unfairLock.deallocate()
}

func get(_ key: Key) -> Value? {
subscript(_ key: Key) -> Value? {
get {
get(key)
}
set(newValue) {
set(key, value: newValue)
}
}

private func get(_ key: Key) -> Value? {
os_unfair_lock_lock(unfairLock)
defer { os_unfair_lock_unlock(unfairLock) }
return storage[key]
}

func set(_ key: Key, value: Value) {
private func set(_ key: Key, value: Value?) {
os_unfair_lock_lock(unfairLock)
defer { os_unfair_lock_unlock(unfairLock) }
storage[key] = value
}

func removeValue(forKey key: Key) {
os_unfair_lock_lock(unfairLock)
defer { os_unfair_lock_unlock(unfairLock) }
_ = storage.removeValue(forKey: key)
}

var allValues: [Key: Value] {
@discardableResult
func removeValue(forKey key: Key) -> Value? {
os_unfair_lock_lock(unfairLock)
defer { os_unfair_lock_unlock(unfairLock) }
return storage
return storage.removeValue(forKey: key)
}
}

Expand All @@ -77,7 +81,7 @@ class Runner {

let secondsToWait = DispatchTimeInterval.seconds(SocketClient.defaultCommandTimeoutSeconds)
// swiftformat:disable:next redundantSelf
let timeoutResult = Self.waitWithPolling(self.executeNext.get(command.id), toEventually: { $0 == true }, timeout: SocketClient.defaultCommandTimeoutSeconds)
let timeoutResult = Self.waitWithPolling(self.executeNext[command.id], toEventually: { $0 == true }, timeout: SocketClient.defaultCommandTimeoutSeconds)
executeNext.removeValue(forKey: command.id)
let failureMessage = "command didn't execute in: \(SocketClient.defaultCommandTimeoutSeconds) seconds"
let success = testDispatchTimeoutResult(timeoutResult, failureMessage: failureMessage, timeToWait: secondsToWait)
Expand Down Expand Up @@ -198,11 +202,11 @@ extension Runner: SocketClientDelegateProtocol {
returnValue = returnedObject
if let command = currentlyExecutingCommand as? RubyCommand {
if let closureArgumentValue = closureArgumentValue, !closureArgumentValue.isEmpty {
command.performCallback(callbackArg: closureArgumentValue, socket: socketClient) {
self.executeNext.set(command.id, value: true)
command.performCallback(callbackArg: closureArgumentValue, socket: socketClient) { [self] in
executeNext[command.id] = true
}
} else {
executeNext.set(command.id, value: true)
executeNext[command.id] = true
}
}
dispatchGroup.leave()
Expand All @@ -211,14 +215,14 @@ extension Runner: SocketClientDelegateProtocol {
verbose(message: "server acknowledged a cancel request")
dispatchGroup.leave()
if let command = currentlyExecutingCommand as? RubyCommand {
executeNext.set(command.id, value: true)
executeNext[command.id] = true
}
completion(socketClient)
case .alreadyClosedSockets, .connectionFailure, .malformedRequest, .malformedResponse, .serverError:
log(message: "error encountered while executing command:\n\(serverResponse)")
dispatchGroup.leave()
if let command = currentlyExecutingCommand as? RubyCommand {
executeNext.set(command.id, value: true)
executeNext[command.id] = true
}
completion(socketClient)
case let .commandTimeout(timeout):
Expand Down

0 comments on commit 214d2e2

Please sign in to comment.