I have code that I am repeating a bunch. I want to update things on the main thread, UI stuff.
public func closeGraph() {
DispatchQueue.main.sync{_closeGraph()}
}
That's easy enough, but what if user interaction triggers it and I am already on the main thread. ++ungood.
public func closeGraph() {
if Thread.isMainThread {
_closeGraph()
} else {
DispatchQueue.main.sync{_closeGraph()}
}
}
Oops openGraph() throws...
public func openGraph() throws {
do {
if Thread.isMainThread {
try _openGraph()
} else {
try DispatchQueue.main.sync{try _openGraph()}
}
} catch {
throw error
}
}
Is there a better way to this so i don't have to copy paste it everywhere?