-
Notifications
You must be signed in to change notification settings - Fork 6
Introduce Outcome to replace Promise #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
… condition Signed-off-by: Michael X. Grey <greyxmike@gmail.com>
|
I've updated the PR to also introduce a new struct Similar to Hypothetically if there is a flaw in crossflow's async channel + execution pipeline then there would be some small risk to using |
This PR resolves #17
The API of Promise was rather convoluted. There were numerous states that a promise could be in:
Users were often put in the awkward position of handling every one of those states or willfully ignoring all but one or two of them. There were also use cases where some of these states are known to be impossible for the promise to be in, so we were wasting the mental bandwidth of the user by making them sort through these variants.
This PR replaces all uses of promise with either
tokio::sync::oneshot::Receiveror a newly introducedOutcomestruct. TheOutcomestruct is really just a wrapper aroundtokio::sync::oneshot::Receiver<Result<T, Cancellation>>that allows the user to receive a simpleResult<T, Cancellation>instead ofResult<Result<T, Cancellation>, RecvError>which is what the user would get if we simply handed them a tokio oneshot receiver.An old code snippet using
Promisemight look like this:Using
Outcomethe above code looks like this instead:Here's a list of the newly deprecated functions and their replacements:
Series::take() -> Recipientis replaced bySeries::capture() -> CaptureSeries::take_response() -> Promiseis replaced bySeries::outcome() -> OutcomeChannel::query(_, _) -> Promiseis replaced byChannel::request_outcome(_, _) -> OutcomeChannel::command(_) -> Promiseis replaced byChannel::commands(_) -> ReplyWe'll keep
Promiseand its related APIs for now for backwards compatibility, but they're marked as deprecated. In version 0.1.0 we'll remove all these deprecated functions and structs.The issue of Promise being too complex was first brought to my attention by @luca-della-vedova so I'd be interested in whether you feel this new API is a move in the right direction.