Skip to content

Rename "await" to "tsc_await" #3036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions swift-tools-support-core/Sources/TSCBasic/Await.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
/// should be passed to the async method's completion handler.
/// - Returns: The value wrapped by the async method's result.
/// - Throws: The error wrapped by the async method's result
public func await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
return try await(body).get()
public func tsc_await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
return try tsc_await(body).get()
}

public func await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
public func tsc_await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
let condition = Condition()
var result: T? = nil
body { theResult in
Expand All @@ -34,3 +34,13 @@ public func await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
}
return result!
}

@available(*, deprecated, renamed: "tsc_await")
public func await<T, ErrorType>(_ body: (@escaping (Result<T, ErrorType>) -> Void) -> Void) throws -> T {
return try tsc_await(body).get()
}

@available(*, deprecated, renamed: "tsc_await")
public func await<T>(_ body: (@escaping (T) -> Void) -> Void) -> T {
return tsc_await(body)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class AwaitTests: XCTestCase {
}

func testBasics() throws {
let value = try await { async("Hi", $0) }
let value = try tsc_await { async("Hi", $0) }
XCTAssertEqual("Hi", value)

do {
let value = try await { throwingAsync("Hi", $0) }
let value = try tsc_await { throwingAsync("Hi", $0) }
XCTFail("Unexpected success \(value)")
} catch {
XCTAssertEqual(error as? DummyError, DummyError.error)
Expand Down