Skip to content

Commit

Permalink
[REFACTOR] completion 대신 continuation 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
LURKS02 committed Nov 29, 2024
1 parent 46c17ed commit 3f129ab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
27 changes: 13 additions & 14 deletions Data/Data/SharingVideoRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,20 @@ private extension SharingVideoRepository {
}

func sendFiles(fileNames: [String], to peerID: String, isRequested: Bool) {
guard !fileNames.isEmpty else {
sendResponse(isRequested: isRequested, to: peerID)
return
}

for index in fileNames.indices {
let fileName = fileNames[index]
let fileURL = FileSystemManager.shared.folder.appending(component: fileName)
let completion: (((any Error)?) -> Void)? = (index == fileNames.count - 1) ? { _ in
self.sendResponse(isRequested: isRequested, to: peerID) } : nil
Task {
for index in fileNames.indices {
let fileName = fileNames[index]
let fileURL = FileSystemManager.shared.folder.appending(component: fileName)
await socketProvider.sendResource(url: fileURL,
resourceName: fileName,
to: peerID)
sendSyncFlags[peerID] = true
}

socketProvider.sendResource(url: fileURL,
resourceName: fileName,
to: peerID,
completion: completion)
if isRequested {
sendReceivedResponse(to: peerID)
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions Data/P2PSocket/SocketProvidable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public protocol SocketResourceSendable {
func sendResource(
url localURL: URL,
resourceName: String,
to peerID: String,
completion: (((any Error)?) -> Void)?
)
to peerID: String
) async
/// 연결된 모든 Peer들에게 리소스를 전송합니다.
func sendResourceToAll(url: URL, resourceName: String) async throws
/// Peer들과 공유한 모든 리소스를 리턴합니다.
Expand Down
7 changes: 2 additions & 5 deletions Data/P2PSocket/SocketProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,14 @@ public extension SocketProvider {
func sendResource(
url localURL: URL,
resourceName: String,
to peerID: String,
completion: (((any Error)?) -> Void)? = nil
) {
to peerID: String) async {
let uuid = UUID()
let nameWithUUID = [resourceName, uuid.uuidString].joined(separator: "/")
guard let mcPeerID = MCPeerIDStorage.shared.peerIDByIdentifier[peerID]?.id else { return }

session.sendResource(at: localURL,
withName: nameWithUUID,
toPeer: mcPeerID,
withCompletionHandler: completion)
toPeer: mcPeerID)
}

func sendResourceToAll(url localUrl: URL, resourceName: String) async throws {
Expand Down

0 comments on commit 3f129ab

Please sign in to comment.