Skip to content

Commit b3b033e

Browse files
authored
Merge branch 'main' into do-not-fail-on-timeout-when-continuous
2 parents 2cb9d0b + ae0648d commit b3b033e

File tree

6 files changed

+27
-57
lines changed

6 files changed

+27
-57
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ GEM
102102
open4 (1.3.4)
103103
public_suffix (4.0.7)
104104
redcarpet (3.6.0)
105-
rexml (3.3.9)
105+
rexml (3.4.2)
106106
rouge (4.4.0)
107107
ruby-macho (2.5.1)
108108
sassc (2.4.0)

Sources/Nimble/DSL+Require.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public func unwrapa<T>(fileID: String = #fileID, file: FileString = #filePath, l
294294
///
295295
/// - Parameter message: A custom message to use in place of the default one.
296296
/// - Parameter customError: A custom error to throw in place of a ``RequireError``.
297-
public func requireFail(_ message: String? = nil, customError: Error? = nil, fileID: String = #fileID, filePath: FileString = #filePath, line: UInt = #line, column: UInt = #column) throws {
297+
public func requireFail(_ message: String? = nil, customError: Error? = nil, fileID: String = #fileID, filePath: FileString = #filePath, line: UInt = #line, column: UInt = #column) throws -> Never {
298298
let location = SourceLocation(fileID: fileID, filePath: filePath, line: line, column: column)
299299
let handler = NimbleEnvironment.activeInstance.assertionHandler
300300

Sources/Nimble/Utils/AsyncAwait.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#if !os(WASI)
22

3-
#if canImport(CoreFoundation)
4-
import CoreFoundation
5-
#endif
6-
73
import Dispatch
84
import Foundation
95

Sources/Nimble/Utils/AsyncTimerSequence.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#if !os(WASI)
22

3-
#if canImport(CoreFoundation)
4-
import CoreFoundation
5-
#endif
63
import Dispatch
74
import Foundation
85

Sources/Nimble/Utils/PollAwait.swift

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#if !os(WASI)
22

3-
#if canImport(CoreFoundation)
4-
import CoreFoundation
5-
#endif
63
import Dispatch
74
import Foundation
85

@@ -198,48 +195,24 @@ internal class AwaitPromiseBuilder<T> {
198195
let timedOutSem = DispatchSemaphore(value: 0)
199196
let semTimedOutOrBlocked = DispatchSemaphore(value: 0)
200197
semTimedOutOrBlocked.signal()
201-
#if canImport(CoreFoundation)
202-
let runLoop = CFRunLoopGetMain()
203-
#if canImport(Darwin)
204-
let runLoopMode = CFRunLoopMode.defaultMode.rawValue
205-
#else
206-
let runLoopMode = kCFRunLoopDefaultMode
207-
#endif
208-
CFRunLoopPerformBlock(runLoop, runLoopMode) {
209-
if semTimedOutOrBlocked.wait(timeout: .now()) == .success {
210-
timedOutSem.signal()
211-
semTimedOutOrBlocked.signal()
212-
if self.promise.resolveResult(.timedOut) {
213-
CFRunLoopStop(CFRunLoopGetMain())
214-
}
215-
}
216-
}
217-
// potentially interrupt blocking code on run loop to let timeout code run
218-
CFRunLoopStop(runLoop)
219-
#else
220198
let runLoop = RunLoop.main
221199
runLoop.perform(inModes: [.default], block: {
222200
if semTimedOutOrBlocked.wait(timeout: .now()) == .success {
223201
timedOutSem.signal()
224202
semTimedOutOrBlocked.signal()
225203
if self.promise.resolveResult(.timedOut) {
226-
RunLoop.main._stop()
204+
RunLoop.main.stop()
227205
}
228206
}
229207
})
230208
// potentially interrupt blocking code on run loop to let timeout code run
231-
runLoop._stop()
232-
#endif
209+
runLoop.stop()
233210
let now = DispatchTime.now() + forcefullyAbortTimeout.dispatchTimeInterval
234211
let didNotTimeOut = timedOutSem.wait(timeout: now) != .success
235212
let timeoutWasNotTriggered = semTimedOutOrBlocked.wait(timeout: .now()) == .success
236213
if didNotTimeOut && timeoutWasNotTriggered {
237214
if self.promise.resolveResult(isContinuous ? .timedOut : .blockedRunLoop) {
238-
#if canImport(CoreFoundation)
239-
CFRunLoopStop(CFRunLoopGetMain())
240-
#else
241-
RunLoop.main._stop()
242-
#endif
215+
runLoop.stop()
243216
}
244217
}
245218
}
@@ -327,11 +300,7 @@ internal class Awaiter {
327300
if completionCount < 2 {
328301
func completeBlock() {
329302
if promise.resolveResult(.completed(result)) {
330-
#if canImport(CoreFoundation)
331-
CFRunLoopStop(CFRunLoopGetMain())
332-
#else
333-
RunLoop.main._stop()
334-
#endif
303+
RunLoop.main.stop()
335304
}
336305
}
337306

@@ -369,20 +338,12 @@ internal class Awaiter {
369338
do {
370339
if let result = try closure() {
371340
if promise.resolveResult(.completed(result)) {
372-
#if canImport(CoreFoundation)
373-
CFRunLoopStop(CFRunLoopGetCurrent())
374-
#else
375-
RunLoop.current._stop()
376-
#endif
341+
RunLoop.current.stop()
377342
}
378343
}
379344
} catch let error {
380345
if promise.resolveResult(.errorThrown(error)) {
381-
#if canImport(CoreFoundation)
382-
CFRunLoopStop(CFRunLoopGetCurrent())
383-
#else
384-
RunLoop.current._stop()
385-
#endif
346+
RunLoop.current.stop()
386347
}
387348
}
388349
}
@@ -417,4 +378,23 @@ internal func pollBlock(
417378
return result
418379
}
419380

381+
#if canImport(CoreFoundation)
382+
import CoreFoundation
383+
384+
extension RunLoop {
385+
func stop() {
386+
CFRunLoopStop(getCFRunLoop())
387+
}
388+
}
389+
390+
#else
391+
392+
extension RunLoop {
393+
func stop() {
394+
_stop()
395+
}
396+
}
397+
398+
#endif
399+
420400
#endif // #if !os(WASI)

Tests/NimbleTests/PollingTest+Require.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#if !os(WASI)
22

33
import Dispatch
4-
#if canImport(CoreFoundation)
5-
import CoreFoundation
6-
#endif
74
import Foundation
85
import XCTest
96
import Nimble

0 commit comments

Comments
 (0)