-
Notifications
You must be signed in to change notification settings - Fork 433
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
Refactored & Bugfix: startWithSignal
and the hot-to-cold lift
.
#106
Changes from all commits
b68849e
3f88617
f626658
2c387e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,7 +337,8 @@ class SignalProducerSpec: QuickSpec { | |
return | ||
} | ||
|
||
producer.startWithSignal { _, innerDisposable in | ||
producer.startWithSignal { signal, innerDisposable in | ||
signal.observe { _ in } | ||
disposable = innerDisposable | ||
} | ||
|
||
|
@@ -432,7 +433,7 @@ class SignalProducerSpec: QuickSpec { | |
observer = incomingObserver | ||
} | ||
|
||
producer.startWithSignal { _ in } | ||
producer.start() | ||
expect(addedDisposable.isDisposed) == false | ||
|
||
observer.sendCompleted() | ||
|
@@ -448,12 +449,31 @@ class SignalProducerSpec: QuickSpec { | |
observer = incomingObserver | ||
} | ||
|
||
producer.startWithSignal { _ in } | ||
producer.start() | ||
expect(addedDisposable.isDisposed) == false | ||
|
||
observer.send(error: .default) | ||
expect(addedDisposable.isDisposed) == true | ||
} | ||
|
||
it("should dispose of the added disposable if the signal is unretained and unobserved upon exiting the scope") { | ||
let addedDisposable = SimpleDisposable() | ||
|
||
let producer = SignalProducer<Int, TestError> { _, disposable in | ||
disposable += addedDisposable | ||
} | ||
|
||
var started = false | ||
var disposed = false | ||
|
||
producer | ||
.on(started: { started = true }, disposed: { disposed = true }) | ||
.startWithSignal { _ in } | ||
|
||
expect(started) == true | ||
expect(disposed) == true | ||
expect(addedDisposable.isDisposed) == true | ||
} | ||
} | ||
|
||
describe("start") { | ||
|
@@ -1970,6 +1990,7 @@ class SignalProducerSpec: QuickSpec { | |
producer | ||
.observe(on: TestScheduler()) | ||
.startWithSignal { signal, innerDisposable in | ||
signal.observe { _ in } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's this for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under the new signal lifetime semantic, a signal is kept alive only if it is retained or has active observers. So the observer is added to extend the signal's lifetime indefinitely for the termination event outside the closure scope, or otherwise the signal would dispose of itself upon exiting the closure. The fixed bug is kinda related too - a produced signal would dispose of itself when it is not retained and not observed. But then the associated producer disposable would not follow. |
||
downstreamDisposable = innerDisposable | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this is great