-
Notifications
You must be signed in to change notification settings - Fork 28
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
A proposal for ending the wrapping/unwrapping war. #53
Comments
I think I know what you mean by this, but just to be sure, could you tell us what the fulfillment value ("acceptance value"?) of var a = new Future({ accept } => accept(5));
var b = new Future({ accept } => accept(a));
var x = a.when(() => 5);
var y = a.when(() => a);
var z = a.when(() => b); |
I tried reading this but had a hard time understanding in between the cautionary notes and preferences stuff. The idea is to not recursively join promises on I know we're in JavaScript-land but some pseudo type-signatures would really clear this up for me. |
Hey @domenic:
At least that's my read of the design that @tabatkins was gunning for. I'm open to arguments that would make |
Ah. I don't think that's very conceptually coherent :-/. If you want a counterpart to |
My goal here is to remove the strain from Waiting for @tabatkins and @dherman to weigh in. |
Like Dominic, I think that if we were to have a separate
This is the result you'd get if the implementation of But I could be biased because I think that If we're going to have both |
@domenic @sicking Oh goodness, no. That would make it a map, which is much less useful. What I've wanted this whole time is a monadic bind function, which does single-level unwrapping. (Once you have bind, you get map for free.) @slightlyoff That behavior is more predictable, though less generally useful. I might be okay with this - In that case, let's call the function |
👍 https://github.com/puffnfresh/fantasy-land#chain The |
So, some details you missed: ^_^ (Assuming that the new operation is called Your proposal details differentiate between Instead, they should differentiate on the argument side - if the Future contains nested Futures, the |
Anyone willing to create (preferably real-world) JS examples of when & how you'd use one over the other? My first reaction is the single unwrap is weird but feel I'm missing something |
Still hoping @dherman will weigh in, but a few observations:
Thanks. |
@jakearchibald Lots of discussion about this in the various threads. Single-unwrap helps in scenarios where different futures represent fundamentally different types of things. For example, a database retrieval might return a Future, and the thing stored in the database might be a Future. You may want to just wait for the database retrieval to finish and then get to work on the value immediately, rather than having to wait for both of them to finish. This is especially true when we add LazyFuture or whatever, which doesn't start its operation until someone registers a callback. I don't like multi-unwrap at all (unless done explicitly), because I think generally it'll just paper over programming errors, but fuck it, if I can get a good @slightlyoff I don't understand. Your starting post in this thread was attempting to resolve the issue by splitting it into two operations, and now you're trying to suggest that we don't need two operations at all? Don't bait-and-switch me, bro. But no, you can't build |
If only there were an alternative method like
It's just an idea off the top of my head really. |
@shogun70 What you're saying doesn't make any sense. Neither have any connection to the question of nested promises. Returning a Future from a .then() callback is already a useful and accepted pattern - it gets unwrapped and the chained future adopts its state. The question is about returning a Future for a Future. |
@slightlyoff So, the best, most consistent model is this: Futures can stack. No magic, nothing special, you can just wrap anything in a Future, including more Futures. (The treatment of callback return values isn't strictly important, but This solves all problems, forever. If you have a nested Future where the two Futures are substantially different kinds of things, such that you only want to wait for the outer future to finish, not both, you can use This also happens to satisfy people who like monads, because It's possible to build |
So just to report on the TC39 meeting's results, we have made the following changes to a new
I accept that |
Ugh, that's incoherent, though! Setting aside This is just silly. If you want Mark/Domenic's And no, you can't introduce |
It's just functional composition @tabatkins. So,
can receive exactly the same
Assuming
In long hand that would be:
Continuing on:
This approach seems quite straight-forward. I can't see any difficulties for someone who knows enough to need non-default behavior. |
@shogun70 I've argued this with you in the mailing list, and won't repeat it here. Your proposal is less convenient for common cases, in return for being slightly more convenient for interfacing with legacy callback APIs. It doesn't match any of the major promise libraries. |
You are reacting to a non-essential implication of my proposal which I haven't even mentioned in this discussion. Lower-level alternatives for And they provide more flexibility, including the feature you are after. Why is it up to the API to say that JS devs will only want the default behavior? You are very aware that some JS devs want non-default behavior, because you are one of those people. Why limit that non-default behavior to only one option, when you can leave that decision to the coder? |
Every time I read these javascript discussions on Rather, I wish to stand in place and defend the utility of the forgotten future function. The following table demonstrates the relevant functoriality to this discussion.
Please do not forget my friend, |
Indeed, Future has |
The problem with this API is that it is neither intuitive, nor symmetric for the lay man.
I suggest renaming:
These might not be the most elegant names, but they are damn intuitive (at least to me). Please rename the API methods to something more intuitive and symmetric. Thank you! |
Doing this here because the mailing lists have turned into an unfollowable mess.
First, some cautionary notes: this thread will use the terms "wrapping" and "unwrapping" to refer to APIs that treat
Future
s as something other than direct values. Posts here that use different terminology will be edited to conform.Next, please be civil and cordial. Those who don't agree with you aren't bad and they might not even be wrong. Goodwill will get us where we want to go.
OK, down to it:
It seems to me that the contended bit of the design is
.then()
(and by extension,.catch()
). Both pro and anti-unwrapping camps can have their own way at resolution time using.resolve()
and.accept()
respectively. And both have valid points:On top of these points, there are preferences for styles of use. These can't ever be truly enforced with rigor because it's trivial to write wrapping/unwrapping versions of direct functions and vice versa. So there are cultural differences that we must admit with regards to preferred styles of use.
With the caveat that all involved are willing to live-and-let-live, I observe that it is possible to end the current debate in everyone's favor so long as we add a "direct" version of
.then()
. That is to say, one which has the semantics of.accept()
with one level of unwrapping for a returned thenable and not.resolve()
(infinite unwrapping) for values returned from callbacks.I'll submit
.when()
as a straw-man name, but I'm not precious about it.So the question now is: is everyone cc'd here willing to make such live-and-let-live compromise? And if not, why not? And is there some other detail which I've missed?
/cc @domenic @dherman @wycats @annevk @tabatkins @erights
The text was updated successfully, but these errors were encountered: