Skip to content

Commit 5d07081

Browse files
committed
Rename await to awaitPromise
1 parent afa9a1a commit 5d07081

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Objective-C and Swift to facilitate writing asynchronous code.
3838
* [All](g3doc/index.md#all)
3939
* [Always](g3doc/index.md#always)
4040
* [Any](g3doc/index.md#any)
41-
* [Await](g3doc/index.md#await)
41+
* [AwaitPromise](g3doc/index.md#awaitpromise)
4242
* [Delay](g3doc/index.md#delay)
4343
* [Race](g3doc/index.md#race)
4444
* [Recover](g3doc/index.md#recover)

Sources/Promises/Promise+Await.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import FBLPromises
1919
/// - promise: Promise to wait for.
2020
/// - throws: Error the promise was rejected with.
2121
/// - returns: Value the promise was fulfilled with.
22-
public func await<Value>(_ promise: Promise<Value>) throws -> Value {
22+
public func awaitPromise<Value>(_ promise: Promise<Value>) throws -> Value {
2323
var outError: NSError?
2424
let outValue = __FBLPromiseAwait(promise.objCPromise, &outError) as AnyObject
2525
if let error = outError { throw error }

Tests/PromisesTests/Promise+AwaitTests.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ class PromiseAwaitTests: XCTestCase {
2020
func testPromiseAwaitFulfill() {
2121
// Act.
2222
let promise = Promise<Int>(on: .global()) { () -> Int in
23-
let minusFive = try await(Harness.negate(5))
23+
let minusFive = try awaitPromise(Harness.negate(5))
2424
XCTAssertEqual(minusFive, -5)
25-
let twentyFive = try await(Harness.multiply(minusFive, minusFive))
25+
let twentyFive = try awaitPromise(Harness.multiply(minusFive, minusFive))
2626
XCTAssertEqual(twentyFive, 25)
27-
let twenty = try await(Harness.add(twentyFive, minusFive))
27+
let twenty = try awaitPromise(Harness.add(twentyFive, minusFive))
2828
XCTAssertEqual(twenty, 20)
29-
let five = try await(Harness.subtract(twentyFive, twenty))
29+
let five = try awaitPromise(Harness.subtract(twentyFive, twenty))
3030
XCTAssertEqual(five, 5)
31-
let zero = try await(Harness.add(minusFive, five))
31+
let zero = try awaitPromise(Harness.add(minusFive, five))
3232
XCTAssertEqual(zero, 0)
33-
return try await(Harness.multiply(zero, five))
33+
return try awaitPromise(Harness.multiply(zero, five))
3434
}
3535

3636
// Assert.
@@ -42,7 +42,7 @@ class PromiseAwaitTests: XCTestCase {
4242
func testPromiseAwaitReject() {
4343
// Arrange & Act.
4444
let promise = Promise<Int>(on: .global()) {
45-
return try await(Harness.fail(Test.Error.code42))
45+
return try awaitPromise(Harness.fail(Test.Error.code42))
4646
}
4747

4848
// Assert.

g3doc/index.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -1212,9 +1212,9 @@ any( any(p1, p2), any(p3, p4)).then { results in
12121212
}
12131213
```
12141214

1215-
### Await
1215+
### AwaitPromise
12161216

1217-
Using `await` you can synchronously wait for a promise to get resolved
1217+
Using `awaitPromise` you can synchronously wait for a promise to get resolved
12181218
on a different thread. That can be useful for situations when you need
12191219
to mix several results from multiple async routines differently, i.e.
12201220
cannot chain them in a clear pipeline using [`then`](#then),
@@ -1224,12 +1224,12 @@ Swift:
12241224

12251225
```swift
12261226
Promise<Int> {
1227-
let minusFive = try await(calculator.negate(5))
1228-
let twentyFive = try await(calculator.multiply(minusFive, minusFive))
1229-
let twenty = try await(calculator.add(twentyFive, minusFive))
1230-
let five = try await(calculator.subtract(twentyFive, twenty))
1231-
let zero = try await(calculator.add(minusFive, five))
1232-
return try await(calculator.multiply(zero, five))
1227+
let minusFive = try awaitPromise(calculator.negate(5))
1228+
let twentyFive = try awaitPromise(calculator.multiply(minusFive, minusFive))
1229+
let twenty = try awaitPromise(calculator.add(twentyFive, minusFive))
1230+
let five = try awaitPromise(calculator.subtract(twentyFive, twenty))
1231+
let zero = try awaitPromise(calculator.add(minusFive, five))
1232+
return try awaitPromise(calculator.multiply(zero, five))
12331233
}.then { result in
12341234
// ...
12351235
}.catch { error in
@@ -1265,14 +1265,14 @@ Objective-C
12651265
Note: In the above examples it's assumed that all calculator routines are
12661266
executed asynchronously on a background thread, because the promise work block
12671267
is dispatched on a [default queue](#default-dispatch-queue) since no other is
1268-
specified, and so any blocking `await` would cause a deadlock if it waited for
1268+
specified, and so any blocking `awaitPromise` would cause a deadlock if it waited for
12691269
a promise that was going to be resolved on the default queue as well. Generally,
1270-
it's usually safer to use `await` from a global concurrent queue only to avoid
1270+
it's usually safer to use `awaitPromise` from a global concurrent queue only to avoid
12711271
any potential deadlocks. Like so:
12721272
12731273
```swift
12741274
Promise<Int>(on: .global()) {
1275-
try await(object.someAsyncRoutine())
1275+
try awaitPromise(object.someAsyncRoutine())
12761276
}
12771277
```
12781278

0 commit comments

Comments
 (0)