Skip to content

Commit

Permalink
Fix linux behavior diff
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed committed Nov 17, 2023
1 parent 56ad97f commit ffaaf03
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Sources/Segment/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,11 @@ extension OperatingMode {
task()
}
case .synchronous:
// if for some reason, we're told to do all this stuff on
// main, ignore it, and use the default queue. this prevents
// a possible deadlock.
if queue === DispatchQueue.main {
OperatingMode.defaultQueue.asyncAndWait(execute: DispatchWorkItem(block: task))
} else {
queue.asyncAndWait(execute: DispatchWorkItem(block: task))
}
// in synchronous mode, always use our own queue to
// prevent deadlocks.
let workItem = DispatchWorkItem(block: task)
OperatingMode.defaultQueue.asyncAndWait(execute: workItem)
}
}
}

11 changes: 11 additions & 0 deletions Sources/Segment/Utilities/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@

import Foundation

#if os(Linux)
extension DispatchQueue {
func asyncAndWait(execute workItem: DispatchWorkItem) {
async {
workItem.perform()
}
workItem.wait()
}
}
#endif

/// Inquire as to whether we are within a Unit Testing environment.
#if DEBUG
internal var isUnitTesting: Bool = {
Expand Down

0 comments on commit ffaaf03

Please sign in to comment.