Skip to content

Commit 820b528

Browse files
committed
Updated for latest Combine beta API
1 parent a88e1e4 commit 820b528

File tree

8 files changed

+26
-20
lines changed

8 files changed

+26
-20
lines changed

Sources/Common/Utilities/SinkQueue.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class SinkQueue<Sink: Subscriber> {
3434
private var demandRequested = Subscribers.Demand.none
3535
private var demandProcessed = Subscribers.Demand.none
3636
private var demandForwarded = Subscribers.Demand.none
37-
private var demandQueued: Subscribers.Demand { .max(buffer.count) }
3837

3938
private var completion: Subscribers.Completion<Sink.Failure>?
4039
private var isActive: Bool { sink != nil && completion == nil }
@@ -78,13 +77,13 @@ class SinkQueue<Sink: Subscriber> {
7877
demandProcessed += 1
7978
demandRequested += sink.receive(next)
8079
}
81-
if let completion = completion, demandQueued < 1 {
80+
if let completion = completion, buffer.count < 1 {
8281
expediteCompletion(completion)
8382
return .none
8483
}
85-
let spareDemand = max(.none, demandRequested - demandProcessed - demandQueued - demandForwarded)
86-
demandForwarded += spareDemand
87-
return spareDemand
84+
let forwardableDemand = (demandRequested - demandForwarded)
85+
demandForwarded += forwardableDemand
86+
return forwardableDemand
8887
}
8988

9089
func assertPreCompletion() {

Sources/Entwine/Deprecations.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Tristan Celder on 01/07/2019.
6+
//
7+
8+
@available(*, deprecated, renamed: "CancellableBag")
9+
public typealias CancellationBag = CancellableBag

Sources/Entwine/Utilities/CancellationBag.swift renamed to Sources/Entwine/Utilities/CancellableBag.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import Combine
2626

2727
/// A container for cancellables that will be cancelled when the bag is deallocated or cancelled itself
28-
public final class CancellationBag: Cancellable {
28+
public final class CancellableBag: Cancellable {
2929

3030
public init() {}
3131

@@ -47,7 +47,7 @@ public final class CancellationBag: Cancellable {
4747

4848
public extension Cancellable {
4949
/// Adds this cancellable to the passed `CancellationBag`
50-
func cancelled(by cancellationBag: CancellationBag) {
50+
func cancelled(by cancellationBag: CancellableBag) {
5151
cancellationBag.add(self)
5252
}
5353
}

Sources/EntwineTest/TestableSubscriber/DemandLedger.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ extension DemandLedger.Transaction: CustomDebugStringConvertible {
147147

148148
extension Subscribers.Demand {
149149
func prettyDescription() -> String {
150-
guard case .max(let amount) = self else {
150+
guard let max = max else {
151151
return ".unlimited"
152152
}
153-
return ".max(\(amount))"
153+
return ".max(\(max))"
154154
}
155155
}
156156

Sources/EntwineTest/TestableSubscriber/TestableSubscriber.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ public final class TestableSubscriber<Input, Failure: Error> {
9393
func debitDemand(_ demand: Subscribers.Demand) {
9494

9595
let authorized = (demandBalance > .none)
96-
97-
demandBalance -= demand
96+
demandBalance -= authorized ? demand : .none
9897
demands.append((scheduler.now, demandBalance, .debit(authorized: authorized)))
99-
10098
if !authorized {
10199
signalNegativeBalance()
102100
}

Tests/EntwineTestTests/TestableSubscriberTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ final class TestableSubscriberTests: XCTestCase {
188188

189189

190190
let expectedDemandLedger: DemandLedger<VirtualTime> = [
191-
(200, .max( 2), .credit(amount: .max(2))),
192-
(200, .max( 1), .debit(authorized: true)),
193-
(200, .none, .debit(authorized: true)),
194-
(200, .max(-1), .debit(authorized: false)),
191+
(200, .max(2), .credit(amount: .max(2))),
192+
(200, .max(1), .debit(authorized: true)),
193+
(200, .none, .debit(authorized: true)),
194+
(200, .none, .debit(authorized: false)),
195195
]
196196

197197
XCTAssertEqual(expectedDemandLedger, testableSubscriber.demands)

Tests/EntwineTests/CancellationBagTests.swift renamed to Tests/EntwineTests/CancellableBagTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ import Combine
2828
@testable import Entwine
2929
@testable import EntwineTest
3030

31-
final class CancellationBagTests: XCTestCase {
31+
final class CancellableBagTests: XCTestCase {
3232

3333
func testBagCancelsContainedCancellablesOnDeallocation() {
3434

3535
let scheduler = TestScheduler()
3636
let subject = PassthroughSubject<Int, Never>()
3737
let subscriber = scheduler.createTestableSubscriber(Int.self, Never.self)
3838

39-
var sut: CancellationBag! = CancellationBag()
39+
var sut: CancellableBag! = CancellableBag()
4040

4141
subscriber.cancelled(by: sut)
4242

@@ -61,7 +61,7 @@ final class CancellationBagTests: XCTestCase {
6161
let subject = PassthroughSubject<Int, Never>()
6262
let subscriber = scheduler.createTestableSubscriber(Int.self, Never.self)
6363

64-
let sut = CancellationBag()
64+
let sut = CancellableBag()
6565

6666
subscriber.cancelled(by: sut)
6767

Tests/EntwineTests/MaterializeTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ final class MaterializeTests: XCTestCase {
7474

7575
func testMaterializesJust1() {
7676

77-
let results1 = scheduler.start { Publishers.Just<Int>(1).materialize() }
77+
let results1 = scheduler.start { Just<Int>(1).materialize() }
7878

7979
let expected1: TestSequence<Signal<Int, Never>, Never> = [
8080
(200, .subscription),

0 commit comments

Comments
 (0)