Skip to content

Commit

Permalink
Merge pull request malcommac#80 from malcommac/bug/79-linux-compilati…
Browse files Browse the repository at this point in the history
…on-error

Fixed compilation under Linux Environment
  • Loading branch information
malcommac authored Sep 14, 2020
2 parents 43170f5 + dc6f98a commit a2a0431
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Sources/Hydra/Promise+Await.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,23 @@ public extension Context {
/// Awaits that the given promise fulfilled with its value or throws an error if the promise fails.
///
/// - Parameter promise: target promise
/// - Returns: return the value of the promise
/// - Throws: throw if promise fails
@discardableResult
internal func await<T>(_ promise: Promise<T>) throws -> T {
guard self.queue != DispatchQueue.main else {
// execute a promise on main context does not make sense
// dispatch_semaphore_wait should NOT be called on the main thread.
// more here: https://medium.com/@valentinkalchev/how-to-pause-and-resume-a-sequence-of-mutating-swift-structs-using-dispatch-semaphore-fc98eca55c0#.ipbujy4k2
throw PromiseError.invalidContext
}

/// - Returns: return the value of the promise
/// - Throws: throw if promise fails
@discardableResult
internal func await<T>(_ promise: Promise<T>) throws -> T {
#if os(Linux)
let isNotMainQueue = self.queue.label != DispatchQueue.main.label
#else
let isNotMainQueue = self.queue != DispatchQueue.main
#endif

guard isNotMainQueue else {
// execute a promise on main context does not make sense
// dispatch_semaphore_wait should NOT be called on the main thread.
// more here: https://medium.com/@valentinkalchev/how-to-pause-and-resume-a-sequence-of-mutating-swift-structs-using-dispatch-semaphore-fc98eca55c0#.ipbujy4k2
throw PromiseError.invalidContext
}

var result: T?
var error: Error?

Expand Down

0 comments on commit a2a0431

Please sign in to comment.