Skip to content

Commit

Permalink
style: add swift-format for code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyamahunt committed Jul 14, 2022
1 parent fd075bd commit 001a1d2
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 33 deletions.
17 changes: 17 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1,
"lineLength": 80,
"indentation": {
"spaces": 4
},
"maximumBlankLines": 1,
"respectsExistingLineBreaks": true,
"indentConditionalCompilationBlocks": false,
"rules": {
"AllPublicDeclarationsHaveDocumentation": true,
"NeverForceUnwrap": true,
"NeverUseForceTry": true,
"NoAccessLevelOnExtensionDeclaration": false,
"ValidateDocumentationComments": true
}
}
7 changes: 3 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ let package = Package(
),
],
dependencies: [
.package(
url: "https://github.com/apple/swift-collections.git",
.upToNextMajor(from: "1.0.0")
),
.package(url: "https://github.com/apple/swift-collections.git", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-format", from: "0.50600.1"),
],
targets: [
.target(
Expand Down
2 changes: 1 addition & 1 deletion Sources/AsyncObject/AsyncMutex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public actor AsyncMutex {
} catch {
debugPrint(
"Wait on mutex for continuation task with key: \(key)"
+ " cancelled with error \(error)"
+ " cancelled with error \(error)"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AsyncObject/AsyncSemaphore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ actor AsyncSemaphore {
} catch {
debugPrint(
"Wait on semaphore for continuation task with key: \(key)"
+ " cancelled with error \(error)"
+ " cancelled with error \(error)"
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/AsyncObject/UnsafeContinuationWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ func withUnsafeThrowingContinuationCancellationHandler<T: Sendable>(
wrapper.cancel(withError: CancellationError())
handler(continuation)
} operation: { () -> T in
let value = try await withUnsafeThrowingContinuation { (c: Continuation) in
let value = try await withUnsafeThrowingContinuation {
(c: Continuation) in
wrapper.value = c
fn(c)
}
Expand Down
52 changes: 29 additions & 23 deletions Tests/AsyncObjectTests/AsyncSemaphoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ class AsyncSemaphoreTests: XCTestCase {
withDelay delay: UInt64 = UInt64(5E9),
durationInSeconds seconds: Int = 0
) async throws {
try await checkExecInterval(for: {
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<count {
group.addTask {
await semaphore.wait()
try await Task.sleep(nanoseconds: delay)
await semaphore.signal()
try await checkExecInterval(
for: {
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<count {
group.addTask {
await semaphore.wait()
try await Task.sleep(nanoseconds: delay)
await semaphore.signal()
}
}
try await group.waitForAll()
}
try await group.waitForAll()
}
}, durationInSeconds: seconds)
}, durationInSeconds: seconds)
}

func checkSemaphoreWaitWithTimeOut(
Expand All @@ -45,20 +46,26 @@ class AsyncSemaphoreTests: XCTestCase {
) async throws {
let semaphore = AsyncSemaphore(value: value)
let store = TaskTimeoutStore()
try await checkExecInterval(for: {
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<count {
group.addTask {
let result = await semaphore.wait(forNanoseconds: timeout)
result == .success ? await store.addSuccess() : await store.addFailure()
try await Task.sleep(nanoseconds: delay)
await semaphore.signal()
try await checkExecInterval(
for: {
try await withThrowingTaskGroup(of: Void.self) { group in
for _ in 0..<count {
group.addTask {
let result = await semaphore.wait(
forNanoseconds: timeout)
result == .success
? await store.addSuccess()
: await store.addFailure()
try await Task.sleep(nanoseconds: delay)
await semaphore.signal()
}
}
try await group.waitForAll()
}
try await group.waitForAll()
}
}, durationInSeconds: seconds)
let (successes, failures) = (await store.successes, await store.failures)
}, durationInSeconds: seconds)
let (successes, failures) = (
await store.successes, await store.failures
)
XCTAssertEqual(successes, value)
XCTAssertEqual(failures, UInt(count) - value)
}
Expand Down Expand Up @@ -115,5 +122,4 @@ class AsyncSemaphoreTests: XCTestCase {
durationInSeconds: 8
)
}

}
6 changes: 3 additions & 3 deletions Tests/AsyncObjectTests/XCTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ extension XCTestCase {
case .seconds(let value):
XCTAssertEqual(seconds, value)
case .microseconds(let value):
XCTAssertEqual(seconds, value/Int(1E6))
XCTAssertEqual(seconds, value / Int(1E6))
case .milliseconds(let value):
XCTAssertEqual(seconds, value/Int(1E3))
XCTAssertEqual(seconds, value / Int(1E3))
case .nanoseconds(let value):
XCTAssertEqual(seconds, value/Int(1E9))
XCTAssertEqual(seconds, value / Int(1E9))
case .never: fallthrough
@unknown default:
NSException(
Expand Down

0 comments on commit 001a1d2

Please sign in to comment.