-
-
Save jasdev/3390c43d90521009c04d17c96f346b05 to your computer and use it in GitHub Desktop.
Sketch of a possible AnyCancellable.store(in:) thread-safety issue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Combine | |
import Foundation | |
import SwiftUI | |
final class SomeObservableObject: ObservableObject { | |
@Published var count: Int? | |
private var cancellables = Set<AnyCancellable>() | |
func fetchCount() { | |
countPublisher // (Assume it’s defined elsewhere.) | |
.receive(on: DispatchQueue.main) | |
.sink(receiveValue: { [weak self] in self?.count = $0 }) | |
.store(in: &cancellables) // Very likely triggers a `Set.insert(_:)` call | |
// under the hood. | |
// https://github.com/OpenCombine/OpenCombine/blob/28993ae57de5a4ea7e164787636cafad442d568c/Sources/OpenCombine/AnyCancellable.swift#L48-L65 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment