1 import Foundation
2 import XCTest
3 
4 class DevMenuLooper {
runMainLoopnull5   static func runMainLoop(for sec: Double) {
6     RunLoop.main.run(mode: .default, before: Date(timeIntervalSinceNow: sec))
7     RunLoop.main.run(mode: .common, before: Date(timeIntervalSinceNow: sec))
8     RunLoop.main.run(mode: .tracking, before: Date(timeIntervalSinceNow: sec))
9   }
10 
runMainLoopUntilEmptynull11   static func runMainLoopUntilEmpty() {
12     var isEmpty = false
13 
14     DispatchQueue.main.async {
15       isEmpty = true
16     }
17 
18     let timout = Date(timeIntervalSinceNow: DevMenuTestOptions.defaultTimeout)
19     while timout.timeIntervalSinceNow > 0 {
20       if isEmpty {
21         return
22       }
23 
24       DevMenuLooper.runMainLoop(for: DevMenuTestOptions.loopTime)
25     }
26 
27     XCTFail("Wait for main thread timeout.")
28   }
29 }
30