Last active
June 21, 2021 19:19
-
-
Save yakushevichsv/c99110c9946eb38a7c26ccac90b5b89f to your computer and use it in GitHub Desktop.
Contains sample of MainThreadRunnerType's usage
This file contains 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
class Test1: MainThreadRunnerType { | |
func displayMessage(_ text: String) { | |
debugPrint(text) | |
} | |
func displayMessage(optText: String?) { | |
guard let text = optText else { return } | |
displayMessage(text) | |
} | |
func displayEndMessage() { | |
displayMessage("End") | |
} | |
func test() { | |
DispatchQueue.main.async { [weak self] in | |
guard let self = self else { return } | |
//Duplication... | |
self.displayMessage("Typical print ") | |
} | |
/* | |
DispatchQueue.main.async { [weak self] in | |
guard let self = self else { return } | |
.. | |
} | |
*/ | |
//simplified version of execution could be displayed like that: | |
//runOnMainWeakly(method: sSelf.displayMessage | |
let sSelf = type(of: self) | |
runOnMainWeakly(method: sSelf.displayMessage(_:), | |
parameter: "Non typical print") | |
runOnMainWeakly(method: sSelf.displayEndMessage) | |
runOnMainWeakly(method: sSelf.displayMessage(optText:), | |
parameter: "Value" as String?) | |
} | |
} | |
// MARK: - Test2 | |
final class Test2: Test1 { | |
typealias SchedulerType = Test2 | |
func displayMessage2(_ text: String) { | |
debugPrint(text) | |
} | |
override func test() { | |
runOnMainWeakly(method: SchedulerType.displayMessage2(_:), | |
parameter: "Non typical print 2") | |
super.test() | |
} | |
} | |
/* | |
Test1().test() | |
let param: MainThreadRunnerType = Test2() | |
param.runOnMain { | |
Test1().test() | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment