Last active
March 17, 2021 09:27
-
-
Save olbrichj/b0ba51fa274df114c98f4744aa813c38 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func executeOnMain() { | |
if !Thread.isMainThread { | |
DispatchQueue.main.async(execute: {() -> Void in | |
executeOnMain() | |
}) | |
return | |
} | |
// do something | |
} |
updated. sry it took so long
It is still wrong. It should read:
func executeOnMain() {
if !Thread.isMainThread {
DispatchQueue.main.async(execute: {() -> Void in
executeOnMain()
})
return
}
// do something
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doesn't this need a
return
in theif
block?Otherwise, in case of code executing outside the main thread, the
// do something
part will be executed 2 times.