用户必须能够打印他们从表格中选择的一组项目。
我有一个PrintEngine
类,可以创建Observable<Report>
的流程。用户将要打印的大量项目排队,然后PrintEngine
只调用PrintEngine.print(items)
。这些步骤中的每一步都是异步的,取决于另一个:
Request the items -> Show Printer Picker UI -> Print the items -> Acknowledge the items have been printed
我目前正在使用流程,因为我的每个网络请求都返回一个可观察的Report
,其中包含流程步骤之间共享的信息。我打电话给:
class PrintEngine {
static print(items: [Item]) -> Observable<Report> {
return request(items).flatMap(pickPrinter).flatMap(print).flatMap(acknowledge)
}
// ...
static func request(items: [Item]) -> Observable<Report> {...} // network call to get pdf data
static func pickPrinter(report: Report) -> Observable<Report> {...} // UIPrinterPickerController UI asynchrony
static func print(report: Report) -> Observable<Report> {...} // Printing the actual data
static func acknowledge(report: Report) -> Observable<Report> {...} // network call to notify server of print outcome
}
在我的View Controller中调用网站:
@IBAction func printQueue() {
// `items` is from the View Controller
PrintEngine.print(items).subscribeNext { _ in
print("External On Next.")
}
}
但这仅打印
"External On Next."
而不是
"External On Next."
"External On Next."
"External On Next."
"External On Next."
subscribeNext
事件后触发我的onNext
块?