Files
GLEGram-iOS/submodules/SSignalKit/SwiftSignalKit/Source/ValuePipe.swift
T
Leeksov 4647310322 GLEGram 12.5 — Initial public release
Based on Swiftgram 12.5 (Telegram iOS 12.5).
All GLEGram features ported and organized in GLEGram/ folder.

Features: Ghost Mode, Saved Deleted Messages, Content Protection Bypass,
Font Replacement, Fake Profile, Chat Export, Plugin System, and more.

See CHANGELOG_12.5.md for full details.
2026-04-06 09:48:12 +03:00

40 lines
1.1 KiB
Swift

import Foundation
public final class ValuePipe<T> {
private let subscribers = Atomic(value: Bag<(T) -> Void>())
public init() {
}
public func signal() -> Signal<T, NoError> {
return Signal { [weak self] subscriber in
if let strongSelf = self {
let index = strongSelf.subscribers.with { value -> Bag<T>.Index in
return value.add { next in
subscriber.putNext(next)
}
}
return ActionDisposable { [weak strongSelf] in
if let strongSelf = strongSelf {
strongSelf.subscribers.with { value -> Void in
value.remove(index)
}
}
}
} else {
return EmptyDisposable
}
}
}
public func putNext(_ next: T) {
let items = self.subscribers.with { value -> [(T) -> Void] in
return value.copyItems()
}
for f in items {
f(next)
}
}
}