I have the following attempt.
The main idea is to .receive(on: queue) operator with private queue
However, it doesn't work as expected.
Is it possible to build event bus queue with combine publishers and subjects?
.
The main idea is to .receive(on: queue) operator with private queue
However, it doesn't work as expected.
Is it possible to build event bus queue with combine publishers and subjects?
.
Code Block swift class Work { var cancellable: AnyCancellable? var cancellable2: AnyCancellable? typealias Input = Int private var inputSubject: PassthroughSubject<Input, Never> = .init() private var inputPublisher: AnyPublisher<Input, Never> init() { let queue: DispatchQueue = .init(label: "com.abc.abc") self.inputPublisher = self.inputSubject.receive(on: queue).eraseToAnyPublisher() self.inputSubject } func handle(_ input: Input) { self.inputSubject.send(input) } func work() { let numbers: [Int] = Array(1...10) self.cancellable2 = self.inputPublisher.sink { (value) in let count: Int = .random(in: 3...5) sleep(UInt32(count)) print(value) } self.cancellable = numbers.publisher.receive(on: DispatchQueue.global()).sink { [weak self] (value) in self?.handle(value) } } }