Combine Framework 的“追加”运算符中值的计时?
Timing of values in Combine Framework's `append` operator?
Combine Framework 的 append
运算符上的 documentation 说:
This operator produces no elements until this publisher finishes. It then produces this publisher’s elements, followed by the given publisher’s elements.
所以我希望第一家出版商的元素能够一次性全部制作出来,而不考虑第一家出版商实际发布它们的时间。但事实并非如此。
例如:
[1,2,3,4].publisher.flatMap(maxPublishers: .max(1)) {
Just([=10=]).delay(for: 1, scheduler: DispatchQueue.main)
}.append( Just(100) )
如您所见,第一个发布者以一秒为间隔生成 1
、2
、3
、4
。根据文档,append
应该 等待 直到所有四个值都已生成——也就是说,等待四秒钟——然后一次重新发布这些值。但事实并非如此。我看到的只是第一个发布者自己生产的东西,即 1
、2
、3
、4
,间隔为一秒。怎么回事?
文档似乎有误。
另一种查看方式是从第一个 从未 完成的发布者开始:
Timer.publish(every: 1, on: .main, in: .common).autoconnect()
.append(Just(Date()))
如果文档是正确的,那根本不会产生任何值,因为第一个发布者永远不会完成。但是它每秒生成第一个发布者的值。
append
(Publishers.Concatenate) 实际使用的策略似乎是这样的:
它订阅第一个发布者并在它们到达时重新发布它的值。
如果并且当它从第一个发布者收到完成的完成时,它会订阅第二个发布者并在它们到达时重新发布它的值。
header 也弄错了:
This operator produces no elements until this publisher finishes.
我的猜测是,在开发的早期阶段,Apple 可能确实按照文档中的描述实施了 .append
(连接),但随后他们意识到这是错误的,并在不更改文档的情况下进行了更改以匹配.
Combine Framework 的 append
运算符上的 documentation 说:
This operator produces no elements until this publisher finishes. It then produces this publisher’s elements, followed by the given publisher’s elements.
所以我希望第一家出版商的元素能够一次性全部制作出来,而不考虑第一家出版商实际发布它们的时间。但事实并非如此。
例如:
[1,2,3,4].publisher.flatMap(maxPublishers: .max(1)) {
Just([=10=]).delay(for: 1, scheduler: DispatchQueue.main)
}.append( Just(100) )
如您所见,第一个发布者以一秒为间隔生成 1
、2
、3
、4
。根据文档,append
应该 等待 直到所有四个值都已生成——也就是说,等待四秒钟——然后一次重新发布这些值。但事实并非如此。我看到的只是第一个发布者自己生产的东西,即 1
、2
、3
、4
,间隔为一秒。怎么回事?
文档似乎有误。
另一种查看方式是从第一个 从未 完成的发布者开始:
Timer.publish(every: 1, on: .main, in: .common).autoconnect()
.append(Just(Date()))
如果文档是正确的,那根本不会产生任何值,因为第一个发布者永远不会完成。但是它每秒生成第一个发布者的值。
append
(Publishers.Concatenate) 实际使用的策略似乎是这样的:
它订阅第一个发布者并在它们到达时重新发布它的值。
如果并且当它从第一个发布者收到完成的完成时,它会订阅第二个发布者并在它们到达时重新发布它的值。
header 也弄错了:
This operator produces no elements until this publisher finishes.
我的猜测是,在开发的早期阶段,Apple 可能确实按照文档中的描述实施了 .append
(连接),但随后他们意识到这是错误的,并在不更改文档的情况下进行了更改以匹配.