Closed guest20 closed 7 months ago
I'm afraid PRs without tests cannot be considered.
I do think we should do some work in this area, however, I would rather deprecate promises returning multiple values, opting instead to require promises returning only one value, which could be an array ref. Returning a collection of values would firm up the choice to allow multiple.
The reason is async/await. Consider the scalar context use currently:
# current
my $value = await get_p();
# collection
my $value = (await get_p())->first;
that seems like a clear loss in functionality. In list-ish context it does make some more sense I suppose but personally I'd rather just not deal with it by requiring a single return
Follow up: rereading, I see that your PR only affects each individual response from ::all
but not the overall return from a promise, including the promise returned by ::all
itself. I suppose that's less obtrusive than my example above, however, it still would set up that expectation that promises can return multiple values. If we wanted to do that, I'd probably want to be consistent with it and get a collection as the result of the all as well, that way I could easily call ->flatten
on the whole thing, which is what I would usually do. Still I'd rather just require only one return and ::all
could just return a naturally flat arrayref
I haven't benchmarked this, but I expect a collection would slow down promises even more, so unless I'm mistaken I'm not very positive to this change.
Looks like no more updates are being made to the proposal. As it stands this seems like a pretty clear rejection.
Summary
pass
Mojo::Collection
s to->then
callbacks when they receive the results of multiplePromise
sMotivation
Being able to call
->first
instead of using->[0]
on the array-ref I receive:Other considerations
Mojo::Collection->new
and thebless
inside cost CPU time, but Collections are cool, so it's a toss up.Mojo::Collection
s already behave like array-refs, so this change will only upset code that checksref
or relies on how array-refs stringify.ref
on the arguments to these callbacks when the current test looks like this: https://github.com/mojolicious/mojo/blob/75124ab7b0e27dc647304067110c2effacc453cf/t/mojo/promise.t#L329