-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored operatingMode related code. (#328)
* Refactoring of flush completion. * Catching places where groups/completions/semaphores might not get hit. * Fixed linux tests * Removed debug line; Added fix for long-running ios task.
- Loading branch information
Showing
9 changed files
with
164 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// | ||
// CompletionGroup.swift | ||
// | ||
// | ||
// Created by Brandon Sneed on 4/17/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class CompletionGroup { | ||
let queue: DispatchQueue | ||
var items = [(DispatchGroup) -> Void]() | ||
|
||
init(queue: DispatchQueue) { | ||
self.queue = queue | ||
} | ||
|
||
func add(workItem: @escaping (DispatchGroup) -> Void) { | ||
items.append(workItem) | ||
} | ||
|
||
func run(mode: OperatingMode, completion: @escaping () -> Void) { | ||
// capture self strongly on purpose | ||
let task: () -> Void = { [self] in | ||
let group = DispatchGroup() | ||
group.enter() | ||
group.notify(queue: queue) { [weak self] in | ||
completion() | ||
self?.items.removeAll() | ||
} | ||
|
||
for item in items { | ||
item(group) | ||
} | ||
|
||
group.leave() | ||
|
||
if mode == .synchronous { | ||
group.wait() | ||
} | ||
} | ||
|
||
switch mode { | ||
case .synchronous: | ||
queue.sync { | ||
task() | ||
} | ||
case .asynchronous: | ||
queue.async { | ||
task() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,4 +85,3 @@ internal func eventStorageDirectory(writeKey: String) -> URL { | |
return segmentURL | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.