在Combine中,有(其中包括)这两个发布者:
new_stages = A.in_edge(c, data='stages')
stages = B.node[p]['stages']
stages.append(new_stages)
<<Update node p to have name of c??>>
B.add_node(p, stages=new_stage_set)
这两个在放入let just = Just("Just")
let future = Future<String, Never>({ (promise) in
DispatchQueue.main.async {
promise(.success("Future"))
}
})
发布者中时具有不同的输出,如下所示
combineLatest
是否可以通过某种方式(例如,操作员)修改just.combineLatest([1,2,3].publisher).sink { (value) in
print(value)
}.store(in: &bin)
/* prints
("Just", 1)
("Just", 2)
("Just", 3)
*/
future.combineLatest([1,2,3].publisher).sink { (value) in
print(value)
}.store(in: &bin)
/* prints:
("Future", 3)
*/
发布者,使其表现得像Future
发布者?
答案 0 :(得分:0)
Future
的行为与您调用combineLatest
时没有什么不同。由于您在Future
中添加了异步分派,因此您的示例只是有缺陷。
combineLatest
仅在其所有上游都发出值时才发出值。因此,如果在DispatchQueue.main.async
内调用promise
之前添加Future
,则会延迟Future
中的发射。因此,Future
的发出要晚于Array.publisher
,因此您只会看到{{1}的输出1(有时是0,具体取决于何时执行主线程上的下一个运行循环)。 }}。
删除异步调用后,您会从combineLatest
和Future
看到相同的输出。
Just