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

Fixed a bug in on which caused the signal to be disposed of too early. #80

Merged
merged 2 commits into from
Nov 5, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Sources/SignalProducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ extension SignalProducerProtocol {

self.startWithSignal { signal, disposable in
compositeDisposable += disposable
compositeDisposable += signal
signal
.on(
event: event,
failed: failed,
Expand Down
36 changes: 36 additions & 0 deletions Tests/ReactiveSwiftTests/SignalProducerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1419,14 +1419,19 @@ class SignalProducerSpec: QuickSpec {
var execute: ((FlattenStrategy) -> Void)!

var innerDisposable = SimpleDisposable()
var isInnerInterrupted = false
var isInnerDisposed = false
var interrupted = false

beforeEach {
execute = { strategy in
let (outerProducer, outerObserver) = SignalProducer<SignalProducer<Int, NoError>, NoError>.pipe()

innerDisposable = SimpleDisposable()
isInnerInterrupted = false
isInnerDisposed = false
let innerProducer = SignalProducer<Int, NoError> { $1.add(innerDisposable) }
.on(interrupted: { isInnerInterrupted = true }, disposed: { isInnerDisposed = true })

interrupted = false
let outerDisposable = outerProducer.flatten(strategy).startWithInterrupted {
Expand All @@ -1446,10 +1451,15 @@ class SignalProducerSpec: QuickSpec {

expect(innerDisposable.isDisposed) == false
expect(interrupted) == false
expect(isInnerInterrupted) == false
expect(isInnerDisposed) == false

disposeOuter()

expect(innerDisposable.isDisposed) == true
expect(interrupted) == true
expect(isInnerInterrupted) == true
expect(isInnerDisposed) == true
}

it("should cancel inner work when disposed after the outer producer completes") {
Expand All @@ -1459,10 +1469,15 @@ class SignalProducerSpec: QuickSpec {

expect(innerDisposable.isDisposed) == false
expect(interrupted) == false
expect(isInnerInterrupted) == false
expect(isInnerDisposed) == false

disposeOuter()

expect(innerDisposable.isDisposed) == true
expect(interrupted) == true
expect(isInnerInterrupted) == true
expect(isInnerDisposed) == true
}
}

Expand All @@ -1472,10 +1487,15 @@ class SignalProducerSpec: QuickSpec {

expect(innerDisposable.isDisposed) == false
expect(interrupted) == false
expect(isInnerInterrupted) == false
expect(isInnerDisposed) == false

disposeOuter()

expect(innerDisposable.isDisposed) == true
expect(interrupted) == true
expect(isInnerInterrupted) == true
expect(isInnerDisposed) == true
}

it("should cancel inner work when disposed after the outer producer completes") {
Expand All @@ -1485,10 +1505,15 @@ class SignalProducerSpec: QuickSpec {

expect(innerDisposable.isDisposed) == false
expect(interrupted) == false
expect(isInnerInterrupted) == false
expect(isInnerDisposed) == false

disposeOuter()

expect(innerDisposable.isDisposed) == true
expect(interrupted) == true
expect(isInnerInterrupted) == true
expect(isInnerDisposed) == true
}
}

Expand All @@ -1498,10 +1523,16 @@ class SignalProducerSpec: QuickSpec {

expect(innerDisposable.isDisposed) == false
expect(interrupted) == false
expect(isInnerInterrupted) == false
expect(isInnerDisposed) == false

disposeOuter()

expect(innerDisposable.isDisposed) == true
expect(interrupted) == true
expect(isInnerInterrupted) == true
expect(isInnerDisposed) == true

}

it("should cancel inner work when disposed after the outer producer completes") {
Expand All @@ -1511,10 +1542,15 @@ class SignalProducerSpec: QuickSpec {

expect(innerDisposable.isDisposed) == false
expect(interrupted) == false
expect(isInnerInterrupted) == false
expect(isInnerDisposed) == false

disposeOuter()

expect(innerDisposable.isDisposed) == true
expect(interrupted) == true
expect(isInnerInterrupted) == true
expect(isInnerDisposed) == true
}
}
}
Expand Down