Skip to content

Commit

Permalink
Apply SwiftFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenviewer committed Jan 23, 2025
1 parent 278b2fe commit f0afc0f
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Sources/Core/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public enum ClientCondition: String {
* `SyncLoop` is a key of the sync loop condition.
*/
case syncLoop = "SyncLoop"

/**
* `WatchLoop` is a key of the watch loop condition.
*/
Expand Down Expand Up @@ -148,7 +148,7 @@ public class Client {
ClientCondition.syncLoop: false,
ClientCondition.watchLoop: false
]

private let syncLoopDuration: Int
private let reconnectStreamDelay: Int
private let maximumAttachmentTimeout: Int
Expand Down Expand Up @@ -221,7 +221,7 @@ public class Client {
throw error
}
}

/**
* `deactivate` deactivates this client.
*/
Expand Down Expand Up @@ -283,7 +283,6 @@ public class Client {
self.semaphoresForInitialzation[docKey] = semaphore

let attachResponse = await self.yorkieService.attachDocument(request: attachRequest, headers: self.authHeader.makeHeader(docKey))


guard attachResponse.error == nil, let message = attachResponse.message else {
throw attachResponse.error ?? YorkieError.rpcError(message: attachResponse.error.debugDescription)
Expand Down Expand Up @@ -420,28 +419,27 @@ public class Client {
throw error
}
}

/**
* `getCondition` returns the condition of this client.
*/
public func getCondition(_ condition: ClientCondition) -> Bool {
return self.conditions[condition] ?? false
}

/**
* `setCondition` set the condition of this client.
*/
public func setCondition(_ condition: ClientCondition, value: Bool) {
self.conditions[condition] = value
}

/**
* `changeSyncMode` changes the synchronization mode of the given document.
*/
@discardableResult
public func changeSyncMode(_ doc: Document, _ syncMode: SyncMode) throws -> Document {
let docKey = doc.getKey()


guard self.isActive else {
throw YorkieError.clientNotActivated(message: "\(docKey) is not active")
Expand Down Expand Up @@ -579,7 +577,7 @@ public class Client {
}
}
}

/**
* `runSyncLoop` runs the sync loop. The sync loop pushes local changes to
* the server and pulls remote changes from the server.
Expand All @@ -598,7 +596,7 @@ public class Client {
self.setCondition(.watchLoop, value: false)
throw YorkieError.clientNotActivated(message: "$\(docKey) is not active")
}

let stream = self.yorkieService.watchDocument(headers: self.authHeader.makeHeader(docKey), onResult: { result in
Task {
switch result {
Expand All @@ -614,7 +612,7 @@ public class Client {
}

Logger.debug("[WD] c:\"\(self.key)\" unwatches")

if await self.handleConnectError(error) {
Logger.warning("[WL] c:\"\(self.key)\" has Error \(String(describing: error))")
try await self.onStreamDisconnect(docKey, with: attachment)
Expand Down Expand Up @@ -823,7 +821,7 @@ public class Client {
throw error
}
}

/**
* `handleConnectError` handles the given error. If the given error can be
* retried after handling, it returns true.
Expand All @@ -833,7 +831,7 @@ public class Client {
guard let connectError = error as? ConnectError else {
return false
}

// NOTE(hackerwins): These errors are retryable.
// Connect guide indicates that for error codes like `ResourceExhausted` and
// `Unavailable`, retries should be attempted following their guidelines.
Expand All @@ -846,7 +844,7 @@ public class Client {
{
return true
}

// NOTE(hackerwins): Some errors should fix the state of the client.
let yorkieErrorCode = YorkieError.Code(rawValue: errorCodeOf(error: connectError))
if yorkieErrorCode == YorkieError.Code.errClientNotActivated ||
Expand All @@ -856,7 +854,7 @@ public class Client {
try self.deactivateInternal()
} catch {}
}

return false
}
}
Expand Down

0 comments on commit f0afc0f

Please sign in to comment.