Pitch: V7 chain-specific default dispatchers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- swift
- Lĩnh vực
- api, backend-api-design
Hướng nghiên cứu
Start by reviewing PromiseKit's existing chain methods and the conf.Q behavior described here. The proposal is complete only after the chain-specific dispatcher API and propagation semantics are agreed; this issue names no implementation files or tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
In RxSwift, dispatching is an attribute of the chain. You switch dispatchers with a separate chain operator, e.g.
observable
.observeOn(MainScheduler.instance)
.subscribe { event in
...
}
...
I believe ReactiveSwift works similarly, but I'm not as familiar with that library.
I love PromiseKit's simple convention of requiring an explicit dispatcher specification for each step in a chain unless you want to use the global default. It's direct and easily understood. I wouldn't want to change this system as the default.
Nevertheless, there's no reason why PromiseKit couldn't also, optionally, allow you to set a default dispatcher for a chain, and there are a couple of nice benefits that would come from this ability.
I'll mention some of the advantages below, but let me first clarify exactly what I'm talking about. Here's a straw-man proposal:
- Promises gain
setDefaultMapDispatcherandsetDefaultReturnDispatchermethods (terrible placeholder names...) with a signature something like
public func setDefaultMapDispatcher(_ on: Dispatcher? = nil) -> Promise<T>
-
As usual, the returned promise is different from the original; it's a wrapper. Only subsequent chain elements added via the wrapper see the new default.
-
Any subsequent method uses the specified default dispatcher if nothing more specific is requested.
conf.Qstill exists but is consulted only if no chain-specific default has been set. -
Methods that return new promises silently propagate the default dispatcher to them.
Benefits
-
Clearer and more self-documenting than
conf.Q. I would hazard a guess that some users initially assume thatconf.Qis consulted at the point of actual dispatch. But in fact, it's consulted at chain construction time through the default argument mechanism. This is useful because it allows differentconf.Qvalues to be set for different regions of code, but it's not very discoverable without experimentation. -
Chains don't affect each other. By contrast, there's only one
conf.Q, and code has to take explicit precautions (save/restore) to avoid fighting over it. -
Code is cleaner without repeating
on:for every clause. -
Purely additive: nothing changes unless you use the feature.
-
Facilitates debugging because you can easily set a temporary default for any portion of a chain. It's one line added or removed which affects no other code. With
conf.Q, you have to add a variable assignment at the start of the chain, stop in the middle of the chain to setconf.Q, then resume the chain from the variable. -
The big one: it allows functions that yield or propagate promises to specify (suggest, really) dispatching policy. Result types that aren't thread-safe can return themselves with dispatching set to a serial queue. For example, a routine that returns a
Promise<NSManagedObject>might set the chain's default dispatcher to aCoreDataDispatcherfor the appropriateNSManagedObjectContextso that the managed object can be freely manipulated with no additional code on the receiver's end. E.g.,
fetchUser(managerID).map { manager in
(manager.firstName, manager.lastName)
}.done { name in
button.setTitle("Email \(name.0) \(name.1)", for: .normal)
}
Thoughts?
- Ngôn ngữ chính
- Swift
- Star
- 14.2k
- Fork
- 1.5k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của mxcl/PromiseKit
-
Allow Serialisation of PMKArrayĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mxcl/PromiseKit#1362 · 1 bình luận · 1 reaction ·
-
CocoaPods supportĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
mxcl/PromiseKit#1361 · 6 bình luận · 2 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
mxcl/PromiseKit#1356 · 3 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
mxcl/PromiseKit#1347 · 5 bình luận · 1 reaction ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
mxcl/PromiseKit#1244 · 1 bình luận · 1 reaction ·
Tất cả issue của mxcl/PromiseKit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
permissionlesstech/bitchat#1743 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
521xueweihan/HelloGitHub#3816 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jamesmontemagno/tiny-clips#378 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
图标看起来比其他应用小一圈Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100