Skip to content

Commit

Permalink
Fixed an issue while calling await() function
Browse files Browse the repository at this point in the history
Due to missing parameters in labels there a bug which avoid calling await without passing the context along with the promise. Right now await specify an in: optional parameter where you will specify the context of the operation.
  • Loading branch information
malcommac committed Feb 20, 2017
1 parent bda4ee9 commit b2323a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Sources/Hydra/Promise+Await.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public prefix func ..!<T> (_ promise: Promise<T>) -> T? {
/// - Returns: fufilled value of the promise
/// - Throws: throws an exception if promise fails due to an error
@discardableResult
public func await<T>(_ context: Context? = nil, _ promise: Promise<T>) throws -> T {
public func await<T>(in context: Context? = nil, _ promise: Promise<T>) throws -> T {
return try (context ?? awaitContext).await(promise)
}

Expand All @@ -79,9 +79,9 @@ public func await<T>(_ context: Context? = nil, _ promise: Promise<T>) throws ->
/// - Returns: the value of the promise
/// - Throws: an exception if operation fails
@discardableResult
public func await<T>(_ context: Context = .background, _ body: @escaping ((_ fulfill: @escaping (T) -> (), _ reject: @escaping (Error) -> () ) throws -> ())) throws -> T {
public func await<T>(in context: Context = .background, _ body: @escaping ((_ fulfill: @escaping (T) -> (), _ reject: @escaping (Error) -> () ) throws -> ())) throws -> T {
let promise = Promise<T>(in: context, body)
return try await(context, promise)
return try await(in: context, promise)
}


Expand Down
3 changes: 2 additions & 1 deletion Tests/HydraTests/HydraTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ class HydraTestThen: XCTestCase {
async(in: .background) {
do {
let startValue = 5
let result1 = try ..self.intPromise(startValue)
// let result1 = try ..self.intPromise(startValue)
let result1 = try await(self.intPromise(startValue))
let result2 = try ..self.intPromiseDelay(result1 * 2, delay: 0.5)
let result3 = try ..self.intPromiseDelay(result2 * 2, delay: 0.5)
if result3 == startValue * 4 {
Expand Down

0 comments on commit b2323a9

Please sign in to comment.