Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- import Combine
- struct MyPublisher: Publisher {
- typealias Output = Int
- typealias Failure = Error
- func receive<S>(subscriber: S) where S : Subscriber,
- Failure == S.Failure,
- Output == S.Input {
- subscriber.receive(1)
- print("called 1")
- subscriber.receive(2)
- print("called 2")
- subscriber.receive(completion: .finished)
- print("called finish")
- }
- }
- MyPublisher()
- .receive(on: RunLoop.main)
- // .throttle(for: .milliseconds(1000), scheduler: RunLoop.main, latest: false)
- // .debounce(for: .milliseconds(1000), scheduler: RunLoop.main)
- // .delay(for: .milliseconds(1000), scheduler: DispatchQueue.main)
- .print()
- .sink(receiveCompletion: { completion in
- switch completion {
- case .finished:
- print("finished")
- case .failure(let error):
- print("error:\(error)")
- }
- }, receiveValue: { num in
- print("\(num)")
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement