Skip to content

Commit

Permalink
Fix build on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Oct 1, 2023
1 parent 00067a9 commit 742b96c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Sources/SwiftyHolidays/CalculationPromise.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#if canImport(Darwin)
import class Dispatch.DispatchSemaphore
#else
@preconcurrency
import class Dispatch.DispatchSemaphore
#endif

/// Represents a value that is currently being calculated.
@usableFromInline
Expand Down
4 changes: 0 additions & 4 deletions Sources/SwiftyHolidays/Gregorian/GregorianCalculator.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#if canImport(Darwin)
import Foundation
#else
@preconcurrency import Foundation // Calendar in Linux
#endif

/// Calculates holiday dates for the gregorian calendar.
public struct GregorianCalculator: Calculator {
Expand Down
34 changes: 34 additions & 0 deletions Tests/SwiftyHolidaysTests/Helpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#if !canImport(Darwin) && swift(<5.9.1)
import XCTest

extension XCTestCase {
/// Wait on an array of expectations for up to the specified timeout, and optionally specify whether they
/// must be fulfilled in the given order. May return early based on fulfillment of the waited on expectations.
///
/// - Parameter expectations: The expectations to wait on.
/// - Parameter timeout: The maximum total time duration to wait on all expectations.
/// - Parameter enforceOrder: Specifies whether the expectations must be fulfilled in the order
/// they are specified in the `expectations` Array. Default is false.
/// - Parameter file: The file name to use in the error message if
/// expectations are not fulfilled before the given timeout. Default is the file
/// containing the call to this method. It is rare to provide this
/// parameter when calling this method.
/// - Parameter line: The line number to use in the error message if the
/// expectations are not fulfilled before the given timeout. Default is the line
/// number of the call to this method in the calling file. It is rare to
/// provide this parameter when calling this method.
///
/// - SeeAlso: XCTWaiter
func fulfillment(of expectations: [XCTestExpectation], timeout: TimeInterval, enforceOrder: Bool = false) async {
await withCheckedContinuation { continuation in
// This function operates by blocking a background thread instead of one owned by libdispatch or by the
// Swift runtime (as used by Swift concurrency.) To ensure we use a thread owned by neither subsystem, use
// Foundation's Thread.detachNewThread(_:).
Thread.detachNewThread { [self] in
wait(for: expectations, timeout: timeout, enforceOrder: enforceOrder)
continuation.resume()
}
}
}
}
#endif

0 comments on commit 742b96c

Please sign in to comment.