Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix-debounce]: should not send values repeatedly #47

Merged
merged 2 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,14 @@ extension Optional where Wrapped: RangeReplaceableCollection {
import Foundation

let env = ProcessInfo.processInfo.environment
let key = "CX_COMBINE_IMPLEMENTATION"
let combineImp = env[key].flatMap(CombineImplementation.init) ?? .default
let impkey = "CX_COMBINE_IMPLEMENTATION"
let isCIKey = "CX_CONTINUOUS_INTEGRATION"

var combineImp = env[impkey].flatMap(CombineImplementation.init) ?? .default
var isCI = env[isCIKey] != nil

// uncommenet the following two lines if you want to test against combine
//combineImp = .combine; isCI = true

package.dependencies.append(contentsOf: combineImp.extraPackageDependencies)

Expand All @@ -120,7 +126,6 @@ for target in package.targets where target.isTest || target.name == "CXTestUtili
target.swiftSettings.append(contentsOf: combineImp.swiftSettings)
}

if combineImp == .combine && env["CX_CONTINUOUS_INTEGRATION"] != nil {
if combineImp == .combine && isCI {
package.platforms = [.macOS("10.15"), .iOS("13.0"), .tvOS("13.0"), .watchOS("6.0")]
}

2 changes: 1 addition & 1 deletion Sources/CXTestUtility/TestScheduler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final class TestScheduler: Scheduler {
self.lock.unlock()
}

return box
return AnyCancellable(box)
}

public func advance(to time: SchedulerTimeType) {
Expand Down
1 change: 1 addition & 0 deletions Sources/CombineX/Publishers/D/Debounce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ extension Publishers.Debounce {
self.lock.unlock()
return
}
self.last = nil
self.demand -= 1
self.lock.unlock()

Expand Down
4 changes: 1 addition & 3 deletions Tests/CombineXTests/Publishers/DebounceSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ class DebounceSpec: QuickSpec {
subject.send(1)
scheduler.advance(by: .seconds(10))

// FIXME: Strange
let expected = Array(repeating: TestSubscriberEvent<Int, TestError>.value(1), count: 10)
expect(sub.events).to(equal(expected))
expect(sub.events).to(equal([.value(1)]))
}

// MARK: 1.3 should send as many values as demand
Expand Down