Created
February 6, 2019 10:09
-
-
Save grigorye/dbbfaddfed71a8bd95621258c04fd3ba to your computer and use it in GitHub Desktop.
RunLoop.main.perform vs DispatchQueue.main.async
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 RunLoopPerformVsDispatchQueueAsyncTests: XCTestCase { | |
func testRunLoopPerformTakesPriorityOverDispatchAsync() { | |
enum Event { | |
case dispatchQueueAsync | |
case runLoopPerform | |
} | |
var events: [Event] = [] | |
DispatchQueue.main.async { | |
events.append(.dispatchQueueAsync) | |
} | |
XCTAssertEqual(events.count, 0) | |
let mainRunLoop = RunLoop.main | |
mainRunLoop.perform { | |
events.append(.runLoopPerform) | |
} | |
XCTAssertEqual(events.count, 0) | |
repeat { | |
mainRunLoop.run(mode: .default, before: .distantPast) | |
} while events.count < 2 | |
XCTAssertEqual(events, [.runLoopPerform, .dispatchQueueAsync]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment