-
Notifications
You must be signed in to change notification settings - Fork 0
/
PublishSubject.swift
36 lines (27 loc) · 1.05 KB
/
PublishSubject.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// Wrapper for `Passthrough Subject` with Failure type locked to `Never`.
final class PublishSubject<Output>: Subject {
public typealias Failure = Never
// MARK: Properties
private let subject = PassthroughSubject<Output, Failure>()
// MARK: Lifecycle
/// - SeeAlso: PassthroughSubject.send(subscription:)
public func send(subscription: Subscription) {
subject.send(subscription: subscription)
}
/// - SeeAlso: PassthroughSubject.receive(subscriber:)
public func receive<S>(subscriber: S) where Output == S.Input, Failure == S.Failure, S: Subscriber {
subject.receive(subscriber: subscriber)
}
/// - SeeAlso: PassthroughSubject.send(_:)
public func send(_ input: Output) {
subject.send(input)
}
/// - SeeAlso: PassthroughSubject.send(completion:)
public func send(completion: Subscribers.Completion<Failure>) {
subject.send(completion: completion)
}
/// - SeeAlso: PassthroughSubject.send()
public func send() where Output == Void {
subject.send()
}
}