實例方法
drop(until
drop(untilOutputFrom:)
忽略來自上遊發布者的元素,直到它接收到來自第二個發布者的元素。
聲明
func drop<P>(untilOutputFrom publisher: P) -> Publishers.DropUntilOutput<Self, P> where P : Publisher, Self.Failure == P.Failure
返回值
發布者從上遊發布者中刪除元素,直到 other
發布者產生一個值。
參數
publisher
一個發布者來監控它的第一個發出的元素。
詳述
使用 Publisher/drop(untilOutputFrom:)
忽略來自上遊發布者的元素,直到另一個、第二個發布者交付其第一個元素。該發布者向第二個發布者請求單個值,並且它忽略(丟棄)來自上遊發布者的所有元素,直到第二個發布者產生一個值。在第二個發布者生成一個元素後,Publisher/drop(untilOutputFrom:)
取消對第二個發布者的訂閱,並允許來自上遊發布者的事件通過。
此發布者收到上遊發布者的訂閱後,會將來自下遊的背壓請求傳遞給上遊發布者。如果上遊發布者在其他發布者生成項目之前對這些請求采取行動,則該發布者會丟棄它從上遊發布者接收到的元素。
在下麵的示例中,pub1
發布者推遲發布其元素,直到 pub2
發布者交付其第一個元素:
let upstream = PassthroughSubject<Int,Never>()
let second = PassthroughSubject<String,Never>()
cancellable = upstream
.drop(untilOutputFrom: second)
.sink { print("\($0)", terminator: " ") }
upstream.send(1)
upstream.send(2)
second.send("A")
upstream.send(3)
upstream.send(4)
// Prints "3 4"
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Result.Publisher drop(while:)用法及代碼示例
- Swift Result.Publisher dropFirst(_:)用法及代碼示例
- Swift Result.Publisher debounce(for:scheduler:options:)用法及代碼示例
- Swift Result.Publisher decode(type:decoder:)用法及代碼示例
- Swift Result.Publisher delay(for:tolerance:scheduler:options:)用法及代碼示例
- Swift Result.Publisher zip(_:_:_:)用法及代碼示例
- Swift Result.Publisher tryLast(where:)用法及代碼示例
- Swift Result.Publisher sink(receiveCompletion:receiveValue:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:)用法及代碼示例
- Swift Result.Publisher tryCompactMap(_:)用法及代碼示例
- Swift Result.Publisher print(_:to:)用法及代碼示例
- Swift Result.Publisher sink(receiveValue:)用法及代碼示例
- Swift Result.Publisher eraseToAnyPublisher()用法及代碼示例
- Swift Result.Publisher setFailureType(to:)用法及代碼示例
- Swift Result.Publisher first(where:)用法及代碼示例
- Swift Result.Publisher output(at:)用法及代碼示例
- Swift Result.Publisher tryCatch(_:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:_:_:_:_:)用法及代碼示例
- Swift Result.Publisher flatMap(maxPublishers:_:)用法及代碼示例
- Swift Result.Publisher map(_:_:_:)用法及代碼示例
- Swift Result.Publisher catch(_:)用法及代碼示例
- Swift Result.Publisher prefix(_:)用法及代碼示例
- Swift Result.Publisher timeout(_:scheduler:options:customError:)用法及代碼示例
- Swift Result.Publisher merge(with:_:)用法及代碼示例
- Swift Result.Publisher map(_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Result.Publisher drop(untilOutputFrom:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。