Skip to content

Commit 43386f7

Browse files
authored
Add bin/format.sh (#3)
1 parent 69c2802 commit 43386f7

File tree

7 files changed

+55
-22
lines changed

7 files changed

+55
-22
lines changed

.swift-version

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5.6.0
2+

.swiftformat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--funcattributes prev-line
2+
--minversion 0.47.2
3+
--maxwidth 96
4+
--typeattributes prev-line
5+
--wraparguments before-first
6+
--wrapparameters before-first
7+
--wrapcollections before-first

Package.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.5
1+
// swift-tools-version:5.6
22
import PackageDescription
33

44
let package = Package(
@@ -9,24 +9,30 @@ let package = Package(
99
products: [
1010
.library(
1111
name: "DispatchTimer",
12-
targets: ["DispatchTimer"])],
12+
targets: ["DispatchTimer"]
13+
),
14+
],
1315
dependencies: [
1416
.package(
15-
name: "Synchronized",
1617
url: "https://github.com/shareup/synchronized.git",
17-
from: "3.1.0")],
18+
from: "3.1.0"
19+
),
20+
],
1821
targets: [
1922
.target(
2023
name: "DispatchTimer",
21-
dependencies: ["Synchronized"],
24+
dependencies: [
25+
.product(name: "Synchronized", package: "synchronized"),
26+
],
2227
swiftSettings: [
2328
.unsafeFlags([
2429
"-Xfrontend", "-warn-concurrency",
2530
]),
26-
]),
31+
]
32+
),
2733
.testTarget(
2834
name: "DispatchTimerTests",
29-
dependencies: ["DispatchTimer"]),
35+
dependencies: ["DispatchTimer"]
36+
),
3037
]
3138
)
32-

Sources/DispatchTimer/DispatchTimer.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ public final class DispatchTimer: Sendable {
1010
public var nextDeadline: DispatchTime {
1111
_nextDeadline.access { $0 }
1212
}
13+
1314
private let _nextDeadline: Locked<DispatchTime>
1415

1516
public init(
1617
_ interval: DispatchTimeInterval,
1718
repeat shouldRepeat: Bool = false,
1819
block: @escaping @Sendable () -> Void
1920
) {
20-
self.source = DispatchSource.makeTimerSource()
21+
source = DispatchSource.makeTimerSource()
2122
self.block = block
22-
self.isRepeating = shouldRepeat
23+
isRepeating = shouldRepeat
2324

2425
let deadline = DispatchTime.now().advanced(by: interval)
2526
_nextDeadline = Locked(deadline)
@@ -46,9 +47,9 @@ public final class DispatchTimer: Sendable {
4647
fireAt deadline: DispatchTime,
4748
block: @escaping @Sendable () -> Void
4849
) {
49-
self.source = DispatchSource.makeTimerSource()
50+
source = DispatchSource.makeTimerSource()
5051
self.block = block
51-
self.isRepeating = false
52+
isRepeating = false
5253
_nextDeadline = Locked(deadline)
5354

5455
let interval = DispatchTime.now().distance(to: deadline)
@@ -75,13 +76,13 @@ public final class DispatchTimer: Sendable {
7576
private extension DispatchTimer {
7677
static func defaultTolerance(_ interval: DispatchTimeInterval) -> DispatchTimeInterval {
7778
switch interval {
78-
case .seconds(let amount):
79+
case let .seconds(amount):
7980
guard amount > 0 else { return .never }
8081
return .milliseconds(oneTenthOfOneThousand(of: amount))
81-
case .milliseconds(let amount):
82+
case let .milliseconds(amount):
8283
guard amount > 0 else { return .never }
8384
return .microseconds(oneTenthOfOneThousand(of: amount))
84-
case .microseconds(let amount):
85+
case let .microseconds(amount):
8586
guard amount > 0 else { return .never }
8687
return .nanoseconds(oneTenthOfOneThousand(of: amount))
8788
case .nanoseconds, .never:
@@ -98,5 +99,5 @@ private extension DispatchTimer {
9899
}
99100

100101
private func oneTenthOfOneThousand(of amount: Int) -> Int {
101-
return Int((Double(amount * 1000) * 0.1).rounded())
102+
Int((Double(amount * 1000) * 0.1).rounded())
102103
}

Tests/DispatchTimerTests/DispatchTimerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import XCTest
21
@testable import DispatchTimer
2+
import XCTest
33

44
final class DispatchTimerTests: XCTestCase {
55
func testNonRepeatingTimer() throws {
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import XCTest
22

33
#if !canImport(ObjectiveC)
4-
public func allTests() -> [XCTestCaseEntry] {
5-
return [
6-
testCase(DispatchTimerTests.allTests),
7-
]
8-
}
4+
public func allTests() -> [XCTestCaseEntry] {
5+
[
6+
testCase(DispatchTimerTests.allTests),
7+
]
8+
}
99
#endif

bin/format.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SELF=`realpath $0`
6+
DIR=`dirname $SELF`
7+
DEV_DIR=`echo ${DIR%/*}`
8+
9+
pushd "$DEV_DIR" &>/dev/null
10+
11+
if command -v swiftformat >/dev/null 2>&1; then
12+
swiftformat --quiet --config .swiftformat .
13+
else
14+
echo "warning: Install swiftformat by running 'brew install swiftformat'"
15+
fi
16+
17+
popd &>/dev/null

0 commit comments

Comments
 (0)