Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
royjit committed Apr 17, 2023
1 parent 2d282ec commit 291fa6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ extension RealtimeConnectionProvider: ConnectionInterceptable {
completion: @escaping (AppSyncConnectionRequest) -> Void
) {
chainInterceptors(
index: 0,
iterator: connectionInterceptors.makeIterator(),
request: request,
endpoint: endpoint,
completion: completion
)
}

private func chainInterceptors(
index: Int,
private func chainInterceptors<I: IteratorProtocol>(
iterator: I,
request: AppSyncConnectionRequest,
endpoint: URL,
completion: @escaping (AppSyncConnectionRequest) -> Void
) {
) where I.Element == ConnectionInterceptor {

guard index < connectionInterceptors.count else {
var mutableIterator = iterator
guard let interceptor = mutableIterator.next() else {
completion(request)
return
}
let interceptor = connectionInterceptors[index]
interceptor.interceptConnection(request, for: endpoint) { interceptedRequest in
self.chainInterceptors(
index: index + 1,
iterator: mutableIterator,
request: interceptedRequest,
endpoint: endpoint,
completion: completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,28 @@ extension RealtimeConnectionProvider: MessageInterceptable {
) {

chainInterceptors(
index: 0,
iterator: messageInterceptors.makeIterator(),
message: message,
endpoint: endpoint,
completion: completion
)
}

private func chainInterceptors(
index: Int,
private func chainInterceptors<I: IteratorProtocol>(
iterator: I,
message: AppSyncMessage,
endpoint: URL,
completion: @escaping (AppSyncMessage) -> Void
) {
) where I.Element == MessageInterceptor {

guard index < messageInterceptors.count else {
var mutableIterator = iterator
guard let interceptor = mutableIterator.next() else {
completion(message)
return
}
let interceptor = messageInterceptors[index]
interceptor.interceptMessage(message, for: endpoint) { interceptedMessage in
self.chainInterceptors(
index: index + 1,
iterator: mutableIterator,
message: interceptedMessage,
endpoint: endpoint,
completion: completion
Expand Down

0 comments on commit 291fa6f

Please sign in to comment.