Skip to content

Commit 1e91157

Browse files
committed
Fixed issue on linux w/ recursive sync
1 parent 3a42e48 commit 1e91157

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

Sources/Segment/Analytics.swift

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,16 @@ extension OperatingMode {
436436
task()
437437
}
438438
case .server:
439-
// if .main is used, we'll get a lockup calling sync.
440-
// so instead, we're gonna use a worker, as our Dispatch
441-
// mechanisms only work when a queue is in place. Just
442-
// calling the task() wouldn't be enough.
443-
if queue == DispatchQueue.main {
444-
DispatchQueue.global(qos: .utility).sync {
445-
task()
446-
}
447-
} else {
448-
queue.sync {
449-
task()
450-
}
439+
// we need to be careful about doing a sync on the same queue we're running
440+
// on, and we have no way of knowing that. So we're gonna dispatch to a
441+
// safe place elsewhere, and just wait.
442+
let group = DispatchGroup()
443+
group.enter()
444+
DispatchQueue.global(qos: .utility).async {
445+
task()
446+
group.leave()
451447
}
448+
group.wait()
452449
}
453450
}
454451
}

0 commit comments

Comments
 (0)