Skip to content

Commit

Permalink
Fixed issue on linux w/ recursive sync
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed committed Nov 16, 2023
1 parent 3a42e48 commit 1e91157
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Sources/Segment/Analytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,16 @@ extension OperatingMode {
task()
}
case .server:
// if .main is used, we'll get a lockup calling sync.
// so instead, we're gonna use a worker, as our Dispatch
// mechanisms only work when a queue is in place. Just
// calling the task() wouldn't be enough.
if queue == DispatchQueue.main {
DispatchQueue.global(qos: .utility).sync {
task()
}
} else {
queue.sync {
task()
}
// we need to be careful about doing a sync on the same queue we're running
// on, and we have no way of knowing that. So we're gonna dispatch to a
// safe place elsewhere, and just wait.
let group = DispatchGroup()
group.enter()
DispatchQueue.global(qos: .utility).async {
task()
group.leave()
}
group.wait()
}
}
}

0 comments on commit 1e91157

Please sign in to comment.