Skip to content

Commit

Permalink
Updated for latest Combine beta API
Browse files Browse the repository at this point in the history
  • Loading branch information
tcldr committed Jul 3, 2019
1 parent a88e1e4 commit 820b528
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
9 changes: 4 additions & 5 deletions Sources/Common/Utilities/SinkQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class SinkQueue<Sink: Subscriber> {
private var demandRequested = Subscribers.Demand.none
private var demandProcessed = Subscribers.Demand.none
private var demandForwarded = Subscribers.Demand.none
private var demandQueued: Subscribers.Demand { .max(buffer.count) }

private var completion: Subscribers.Completion<Sink.Failure>?
private var isActive: Bool { sink != nil && completion == nil }
Expand Down Expand Up @@ -78,13 +77,13 @@ class SinkQueue<Sink: Subscriber> {
demandProcessed += 1
demandRequested += sink.receive(next)
}
if let completion = completion, demandQueued < 1 {
if let completion = completion, buffer.count < 1 {
expediteCompletion(completion)
return .none
}
let spareDemand = max(.none, demandRequested - demandProcessed - demandQueued - demandForwarded)
demandForwarded += spareDemand
return spareDemand
let forwardableDemand = (demandRequested - demandForwarded)
demandForwarded += forwardableDemand
return forwardableDemand
}

func assertPreCompletion() {
Expand Down
9 changes: 9 additions & 0 deletions Sources/Entwine/Deprecations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// File.swift
//
//
// Created by Tristan Celder on 01/07/2019.
//

@available(*, deprecated, renamed: "CancellableBag")
public typealias CancellationBag = CancellableBag
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Combine

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

public init() {}

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

public extension Cancellable {
/// Adds this cancellable to the passed `CancellationBag`
func cancelled(by cancellationBag: CancellationBag) {
func cancelled(by cancellationBag: CancellableBag) {
cancellationBag.add(self)
}
}
4 changes: 2 additions & 2 deletions Sources/EntwineTest/TestableSubscriber/DemandLedger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ extension DemandLedger.Transaction: CustomDebugStringConvertible {

extension Subscribers.Demand {
func prettyDescription() -> String {
guard case .max(let amount) = self else {
guard let max = max else {
return ".unlimited"
}
return ".max(\(amount))"
return ".max(\(max))"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ public final class TestableSubscriber<Input, Failure: Error> {
func debitDemand(_ demand: Subscribers.Demand) {

let authorized = (demandBalance > .none)

demandBalance -= demand
demandBalance -= authorized ? demand : .none
demands.append((scheduler.now, demandBalance, .debit(authorized: authorized)))

if !authorized {
signalNegativeBalance()
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/EntwineTestTests/TestableSubscriberTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ final class TestableSubscriberTests: XCTestCase {


let expectedDemandLedger: DemandLedger<VirtualTime> = [
(200, .max( 2), .credit(amount: .max(2))),
(200, .max( 1), .debit(authorized: true)),
(200, .none, .debit(authorized: true)),
(200, .max(-1), .debit(authorized: false)),
(200, .max(2), .credit(amount: .max(2))),
(200, .max(1), .debit(authorized: true)),
(200, .none, .debit(authorized: true)),
(200, .none, .debit(authorized: false)),
]

XCTAssertEqual(expectedDemandLedger, testableSubscriber.demands)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ import Combine
@testable import Entwine
@testable import EntwineTest

final class CancellationBagTests: XCTestCase {
final class CancellableBagTests: XCTestCase {

func testBagCancelsContainedCancellablesOnDeallocation() {

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

var sut: CancellationBag! = CancellationBag()
var sut: CancellableBag! = CancellableBag()

subscriber.cancelled(by: sut)

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

let sut = CancellationBag()
let sut = CancellableBag()

subscriber.cancelled(by: sut)

Expand Down
2 changes: 1 addition & 1 deletion Tests/EntwineTests/MaterializeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class MaterializeTests: XCTestCase {

func testMaterializesJust1() {

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

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

0 comments on commit 820b528

Please sign in to comment.