Skip to content

Commit 001a1d2

Browse files
committed
style: add swift-format for code formatting
1 parent fd075bd commit 001a1d2

File tree

7 files changed

+56
-33
lines changed

7 files changed

+56
-33
lines changed

.swift-format

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": 1,
3+
"lineLength": 80,
4+
"indentation": {
5+
"spaces": 4
6+
},
7+
"maximumBlankLines": 1,
8+
"respectsExistingLineBreaks": true,
9+
"indentConditionalCompilationBlocks": false,
10+
"rules": {
11+
"AllPublicDeclarationsHaveDocumentation": true,
12+
"NeverForceUnwrap": true,
13+
"NeverUseForceTry": true,
14+
"NoAccessLevelOnExtensionDeclaration": false,
15+
"ValidateDocumentationComments": true
16+
}
17+
}

Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ let package = Package(
1717
),
1818
],
1919
dependencies: [
20-
.package(
21-
url: "https://github.com/apple/swift-collections.git",
22-
.upToNextMajor(from: "1.0.0")
23-
),
20+
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.0"),
21+
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
22+
.package(url: "https://github.com/apple/swift-format", from: "0.50600.1"),
2423
],
2524
targets: [
2625
.target(

Sources/AsyncObject/AsyncMutex.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public actor AsyncMutex {
4343
} catch {
4444
debugPrint(
4545
"Wait on mutex for continuation task with key: \(key)"
46-
+ " cancelled with error \(error)"
46+
+ " cancelled with error \(error)"
4747
)
4848
}
4949
}

Sources/AsyncObject/AsyncSemaphore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ actor AsyncSemaphore {
4545
} catch {
4646
debugPrint(
4747
"Wait on semaphore for continuation task with key: \(key)"
48-
+ " cancelled with error \(error)"
48+
+ " cancelled with error \(error)"
4949
)
5050
}
5151
}

Sources/AsyncObject/UnsafeContinuationWrapper.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ func withUnsafeThrowingContinuationCancellationHandler<T: Sendable>(
99
wrapper.cancel(withError: CancellationError())
1010
handler(continuation)
1111
} operation: { () -> T in
12-
let value = try await withUnsafeThrowingContinuation { (c: Continuation) in
12+
let value = try await withUnsafeThrowingContinuation {
13+
(c: Continuation) in
1314
wrapper.value = c
1415
fn(c)
1516
}

Tests/AsyncObjectTests/AsyncSemaphoreTests.swift

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,19 @@ class AsyncSemaphoreTests: XCTestCase {
2222
withDelay delay: UInt64 = UInt64(5E9),
2323
durationInSeconds seconds: Int = 0
2424
) async throws {
25-
try await checkExecInterval(for: {
26-
try await withThrowingTaskGroup(of: Void.self) { group in
27-
for _ in 0..<count {
28-
group.addTask {
29-
await semaphore.wait()
30-
try await Task.sleep(nanoseconds: delay)
31-
await semaphore.signal()
25+
try await checkExecInterval(
26+
for: {
27+
try await withThrowingTaskGroup(of: Void.self) { group in
28+
for _ in 0..<count {
29+
group.addTask {
30+
await semaphore.wait()
31+
try await Task.sleep(nanoseconds: delay)
32+
await semaphore.signal()
33+
}
3234
}
35+
try await group.waitForAll()
3336
}
34-
try await group.waitForAll()
35-
}
36-
}, durationInSeconds: seconds)
37+
}, durationInSeconds: seconds)
3738
}
3839

3940
func checkSemaphoreWaitWithTimeOut(
@@ -45,20 +46,26 @@ class AsyncSemaphoreTests: XCTestCase {
4546
) async throws {
4647
let semaphore = AsyncSemaphore(value: value)
4748
let store = TaskTimeoutStore()
48-
try await checkExecInterval(for: {
49-
try await withThrowingTaskGroup(of: Void.self) { group in
50-
for _ in 0..<count {
51-
group.addTask {
52-
let result = await semaphore.wait(forNanoseconds: timeout)
53-
result == .success ? await store.addSuccess() : await store.addFailure()
54-
try await Task.sleep(nanoseconds: delay)
55-
await semaphore.signal()
49+
try await checkExecInterval(
50+
for: {
51+
try await withThrowingTaskGroup(of: Void.self) { group in
52+
for _ in 0..<count {
53+
group.addTask {
54+
let result = await semaphore.wait(
55+
forNanoseconds: timeout)
56+
result == .success
57+
? await store.addSuccess()
58+
: await store.addFailure()
59+
try await Task.sleep(nanoseconds: delay)
60+
await semaphore.signal()
61+
}
5662
}
63+
try await group.waitForAll()
5764
}
58-
try await group.waitForAll()
59-
}
60-
}, durationInSeconds: seconds)
61-
let (successes, failures) = (await store.successes, await store.failures)
65+
}, durationInSeconds: seconds)
66+
let (successes, failures) = (
67+
await store.successes, await store.failures
68+
)
6269
XCTAssertEqual(successes, value)
6370
XCTAssertEqual(failures, UInt(count) - value)
6471
}
@@ -115,5 +122,4 @@ class AsyncSemaphoreTests: XCTestCase {
115122
durationInSeconds: 8
116123
)
117124
}
118-
119125
}

Tests/AsyncObjectTests/XCTestCase.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ extension XCTestCase {
1212
case .seconds(let value):
1313
XCTAssertEqual(seconds, value)
1414
case .microseconds(let value):
15-
XCTAssertEqual(seconds, value/Int(1E6))
15+
XCTAssertEqual(seconds, value / Int(1E6))
1616
case .milliseconds(let value):
17-
XCTAssertEqual(seconds, value/Int(1E3))
17+
XCTAssertEqual(seconds, value / Int(1E3))
1818
case .nanoseconds(let value):
19-
XCTAssertEqual(seconds, value/Int(1E9))
19+
XCTAssertEqual(seconds, value / Int(1E9))
2020
case .never: fallthrough
2121
@unknown default:
2222
NSException(

0 commit comments

Comments
 (0)