Skip to content

Commit

Permalink
Fix an issue where binding closure could be executed after disposing
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Oct 12, 2021
1 parent 224225f commit 9821826
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Sources/Bindable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ extension SignalProtocol where Error == Never {
/// - Returns: A disposable that can cancel the binding.
@discardableResult
public func bind<Target: Deallocatable>(to target: Target, context: ExecutionContext, setter: @escaping (Target, Element) -> Void) -> Disposable {
return prefix(untilOutputFrom: target.deallocated).observeNext { [weak target] element in
context.execute {
if let target = target {
setter(target, element)
}
return prefix(untilOutputFrom: target.deallocated).receive(on: context).observeNext { [weak target] element in
if let target = target {
setter(target, element)
}
}
}
Expand Down Expand Up @@ -188,11 +186,9 @@ extension SignalProtocol where Error == Never, Element == Void {
/// - Returns: A disposable that can cancel the binding.
@discardableResult
public func bind<Target: Deallocatable>(to target: Target, context: ExecutionContext, setter: @escaping (Target) -> Void) -> Disposable {
return prefix(untilOutputFrom: target.deallocated).observeNext { [weak target] _ in
context.execute {
if let target = target {
setter(target)
}
return prefix(untilOutputFrom: target.deallocated).receive(on: context).observeNext { [weak target] _ in
if let target = target {
setter(target)
}
}
}
Expand Down

0 comments on commit 9821826

Please sign in to comment.