實例方法
subscribe(on:
subscribe(on:options:)
指定在其上執行訂閱、取消和請求操作的調度程序。
聲明
func subscribe<S>(
on scheduler: S,
options: S.SchedulerOptions? = nil
) -> Publishers.SubscribeOn<Self, S> where S : Scheduler
返回值
在指定調度程序上執行上遊操作的發布者。
參數
scheduler
調度程序用於向上遊發布者發送消息。
options
自定義元素交付的選項。
詳述
與影響下遊消息的 Publisher/receive(on:options:)
相比,Publisher/subscribe(on:options:)
更改上遊消息的執行上下文。
在以下示例中,Publisher/subscribe(on:options:)
運算符導致 ioPerformingPublisher
在 backgroundQueue
上接收請求,而 Publisher/receive(on:options:)
導致 uiUpdatingSubscriber
在 RunLoop.main
上接收元素和完成。
let ioPerformingPublisher == // Some publisher.
let uiUpdatingSubscriber == // Some subscriber that updates the UI.
ioPerformingPublisher
.subscribe(on: backgroundQueue)
.receive(on: RunLoop.main)
.subscribe(uiUpdatingSubscriber)
使用 Publisher/subscribe(on:options:)
還會導致上遊發布者使用指定的調度程序執行 Cancellable/cancel()
。
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Result.Publisher sink(receiveCompletion:receiveValue:)用法及代碼示例
- Swift Result.Publisher sink(receiveValue:)用法及代碼示例
- Swift Result.Publisher setFailureType(to:)用法及代碼示例
- Swift Result.Publisher share()用法及代碼示例
- Swift Result.Publisher scan(_:_:)用法及代碼示例
- Swift Result.Publisher zip(_:_:_:)用法及代碼示例
- Swift Result.Publisher tryLast(where:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:)用法及代碼示例
- Swift Result.Publisher tryCompactMap(_:)用法及代碼示例
- Swift Result.Publisher print(_:to:)用法及代碼示例
- Swift Result.Publisher eraseToAnyPublisher()用法及代碼示例
- Swift Result.Publisher first(where:)用法及代碼示例
- Swift Result.Publisher output(at:)用法及代碼示例
- Swift Result.Publisher tryCatch(_:)用法及代碼示例
- Swift Result.Publisher dropFirst(_:)用法及代碼示例
- Swift Result.Publisher merge(with:_:_:_:_:_:_:)用法及代碼示例
- Swift Result.Publisher flatMap(maxPublishers:_:)用法及代碼示例
- Swift Result.Publisher map(_:_:_:)用法及代碼示例
- Swift Result.Publisher catch(_:)用法及代碼示例
- Swift Result.Publisher drop(while:)用法及代碼示例
- Swift Result.Publisher prefix(_:)用法及代碼示例
- Swift Result.Publisher timeout(_:scheduler:options:customError:)用法及代碼示例
- Swift Result.Publisher merge(with:_:)用法及代碼示例
- Swift Result.Publisher map(_:)用法及代碼示例
- Swift Result.Publisher append(_:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Result.Publisher subscribe(on:options:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。