Skip to content

Commit 05a3df9

Browse files
authored
Remove Forever (#13)
* Remove Forever and use Combine’s Sink * Update CI GitHub Action * Replace old GitHub CI Action with newer version * Rename GitHub Action and update Swift version * Add build status SVG to README.md
1 parent 47a106e commit 05a3df9

File tree

7 files changed

+43
-51
lines changed

7 files changed

+43
-51
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
name: ci
2-
on: push
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
39
jobs:
4-
test:
5-
runs-on: macOS-10.14
10+
build:
11+
name: Build and Test
12+
runs-on: macos-latest
13+
614
steps:
7-
- uses: actions/checkout@v1
8-
- name: Switch Xcode to 11.1
9-
run: xcversion select 11.1
10-
- name: Generate Xcode project file
11-
run: swift package generate-xcodeproj
12-
- name: Build
13-
run: xcodebuild -scheme SQLite-Package -destination 'platform=iOS Simulator,name=iPhone 11 Pro,OS=13.1'
14-
- name: Test
15-
run: xcodebuild -scheme SQLite-Package -destination 'platform=iOS Simulator,name=iPhone 11 Pro,OS=13.1' test | xcpretty
15+
- uses: actions/checkout@v2
16+
- name: Build
17+
run: swift build -v
18+
- name: Run tests
19+
run: swift test -v

Package.resolved

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.2
22
import PackageDescription
33

44
let package = Package(
@@ -12,8 +12,7 @@ let package = Package(
1212
targets: ["SQLite"]),
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/shareup/atomic.git", .upToNextMajor(from: "1.0.0")),
16-
.package(url: "https://github.com/shareup/forever.git", .upToNextMajor(from: "0.0.0")),
15+
.package(name: "Atomic", url: "https://github.com/shareup/atomic.git", from: "1.0.0"),
1716
],
1817
targets: [
1918
.target(
@@ -25,7 +24,6 @@ let package = Package(
2524
name: "SQLiteTests",
2625
dependencies: [
2726
"SQLite",
28-
"Forever",
2927
]
3028
),
3129
]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SQLite.Database
22

3-
[![Swift](https://img.shields.io/badge/swift-5.1-green.svg?longCache=true&style=flat)](https://developer.apple.com/swift/)
3+
[![Swift](https://img.shields.io/badge/swift-5.2-green.svg?longCache=true&style=flat)](https://developer.apple.com/swift/)
44
[![License](https://img.shields.io/badge/license-MIT-green.svg?longCache=true&style=flat)](/LICENSE)
5+
![Build](https://github.com/shareup/sqlite/workflows/Build/badge.svg)
56

67
## Introduction
78

Sources/SQLite/SQLite+Database.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ extension SQLite.Database {
277277
}
278278

279279
func notify(observers: Array<SQLite.Observer>) {
280-
_queue.async { [weak self] in
281-
guard let self = self else { return }
280+
_queue.async {
282281
observers.forEach { (observer) in
283282
defer { observer.statement.reset() }
284283
guard let (_, output) = try? observer.statement.evaluate() else { return }

Sources/SQLite/SQLite+Publisher.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private extension SQLite {
3939
final class Subscription: Combine.Subscription {
4040
private let _subscriber: AnySubscriber<Array<SQLiteRow>, Swift.Error>
4141

42-
private var _demand: Subscribers.Demand?
42+
private var _demand: Subscribers.Demand = .none
4343

4444
@Atomic(nil) private var _token: AnyObject?
4545

@@ -48,12 +48,12 @@ private extension SQLite {
4848
}
4949

5050
func request(_ demand: Subscribers.Demand) {
51-
_demand = demand
51+
_demand += demand
5252
}
5353

5454
func cancel() {
5555
_token = nil
56-
_demand = nil
56+
_demand = .none
5757
}
5858

5959
func observe(_ sql: SQL, arguments: SQLiteArguments, queue: DispatchQueue, on database: Database) throws {
@@ -68,9 +68,9 @@ private extension SQLite {
6868

6969
func receive(_ rows: Array<SQLiteRow>) {
7070
guard _token != nil else { return }
71-
guard let demand = _demand else { return }
72-
guard demand > 0 else { return }
73-
_demand = _subscriber.receive(rows)
71+
guard _demand > 0 else { return }
72+
_demand -= rows.count
73+
_demand += _subscriber.receive(rows)
7474
}
7575
}
7676
}

Tests/SQLiteTests/SQLite+PublisherTests.swift

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import XCTest
22
import Combine
3-
import Forever
43
@testable import SQLite
54

65
class SQLitePublisherTests: XCTestCase {
@@ -47,10 +46,10 @@ class SQLitePublisherTests: XCTestCase {
4746

4847
func testCancellingForeverCancelsSubscriptions() {
4948
let publisher: AnyPublisher<Array<Person>, Error> = database.publisher(Person.getAll)
50-
let forever = self.forever(for: publisher, expecting: [[_person1, _person2]])
49+
let sink = self.sink(for: publisher, expecting: [[_person1, _person2]])
5150

5251
self.do({
53-
forever.cancel()
52+
sink.cancel()
5453
try! self.database.write(Person.deleteWithID, arguments: ["id": .text(self._person1.id)])
5554
}, after: 0.05, thenWait: 0.1)
5655
}
@@ -64,10 +63,10 @@ class SQLitePublisherTests: XCTestCase {
6463
]
6564

6665
let publisher: AnyPublisher<Array<SQLiteRow>, Error> = database.publisher(Person.getAll)
67-
let forever = self.forever(for: publisher, expecting: expected, expectation: expectation)
66+
let sink = self.sink(for: publisher, expecting: expected, expectation: expectation)
6867
try! database.write(Person.deleteWithID, arguments: ["id": .text(_person1.id)])
6968
waitForExpectations(timeout: 0.5)
70-
forever.cancel()
69+
sink.cancel()
7170
}
7271

7372
func testDelete() {
@@ -79,10 +78,10 @@ class SQLitePublisherTests: XCTestCase {
7978
]
8079

8180
let publisher: AnyPublisher<Array<Person>, Error> = database.publisher(Person.getAll)
82-
let forever = self.forever(for: publisher, expecting: expected, expectation: expectation)
81+
let sink = self.sink(for: publisher, expecting: expected, expectation: expectation)
8382
try! database.write(Person.deleteWithID, arguments: ["id": .text(_person1.id)])
8483
waitForExpectations(timeout: 0.5)
85-
forever.cancel()
84+
sink.cancel()
8685
}
8786

8887
func testDeleteFirstWhere() {
@@ -92,10 +91,10 @@ class SQLitePublisherTests: XCTestCase {
9291
.filter({ $0.count == 1 })
9392
.eraseToAnyPublisher()
9493

95-
let forever = self.forever(for: publisher, shouldFinish: true, expecting: [[_person2]], expectation: expectation)
94+
let sink = self.sink(for: publisher, shouldFinish: true, expecting: [[_person2]], expectation: expectation)
9695
try! database.write(Person.deleteWithID, arguments: ["id": .text(_person1.id)])
9796
waitForExpectations(timeout: 0.5)
98-
forever.cancel()
97+
sink.cancel()
9998
}
10099

101100
func testDeleteMappedToName() {
@@ -111,10 +110,10 @@ class SQLitePublisherTests: XCTestCase {
111110
.map { $0.map { $0.name } }
112111
.eraseToAnyPublisher()
113112

114-
let forever = self.forever(for: publisher, expecting: expected, expectation: expectation)
113+
let sink = self.sink(for: publisher, expecting: expected, expectation: expectation)
115114
try! database.write(Person.deleteWithID, arguments: ["id": .text(_person1.id)])
116115
waitForExpectations(timeout: 0.5)
117-
forever.cancel()
116+
sink.cancel()
118117
}
119118

120119
func testInsert() {
@@ -134,11 +133,11 @@ class SQLitePublisherTests: XCTestCase {
134133

135134
let publisher: AnyPublisher<Array<PetOwner>, Error> = database.publisher(PetOwner.self, PetOwner.getAll)
136135

137-
let forever = self.forever(for: publisher, expecting: expected, expectation: expectation)
136+
let sink = self.sink(for: publisher, expecting: expected, expectation: expectation)
138137
try! database.write(Person.insert, arguments: person3.asArguments)
139138
try! database.write(Pet.insert, arguments: pet3.asArguments)
140139
waitForExpectations(timeout: 0.5)
141-
forever.cancel()
140+
sink.cancel()
142141
}
143142

144143
static var allTests = [
@@ -197,12 +196,12 @@ private extension SQLitePublisherTests {
197196
}
198197
}
199198

200-
func forever<T: Equatable, E: Error>(
199+
func sink<T: Equatable, E: Error>(
201200
for publisher: AnyPublisher<Array<T>, E>,
202201
shouldFinish: Bool = false,
203202
expecting expected: Array<Array<T>>,
204203
expectation: XCTestExpectation? = nil)
205-
-> Subscribers.Forever<AnyPublisher<Array<T>, E>> {
204+
-> AnyCancellable {
206205
let receiveCompletion: (Subscribers.Completion<E>) -> Void = { completion in
207206
guard shouldFinish, case .finished = completion else {
208207
XCTFail("Should not receive completion: \(String(describing: completion))")
@@ -219,6 +218,6 @@ private extension SQLitePublisherTests {
219218
}
220219
}
221220

222-
return publisher.forever(receiveCompletion: receiveCompletion, receiveValue: receiveValue)
221+
return publisher.sink(receiveCompletion: receiveCompletion, receiveValue: receiveValue)
223222
}
224223
}

0 commit comments

Comments
 (0)