mojolicious / mojo

:sparkles: Mojolicious - Perl real-time web framework

Home Page:https://mojolicious.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected async/await promise behavior in 9.28

jberger opened this issue · comments

  • Mojolicious version: 9.28
  • Perl version: NA
  • Operating system: NA

As explained on IRC, there has at least been a change of behavior, I think it qualifies as a bug as I think what I'm doing is allowed. It seems that in certain circumstances, when returning a promise from an async function, and that async function is awaited elsewhere, that promise can be returned from await, rather than the result of the promise.

My small scale replication is

perl -Mojo -MMojo::Base=-async_await -E 'async sub main { print await doit() } async sub doit { await Mojo::Promise->timer(1); return Mojo::Promise->resolve("hello") } main()->wait'

It should print "hello" but instead in Mojo 9.28 it prints the Mojo::Promise=HASH ... object

note that return Mojo::Promise->resolve("hello") does work, this is why I suspect that the optimization in 9.28 is possibly not handling thenables as it should, however, if doit doesn't have some other async calls in it then it does work too, which is why I wonder if there might be some race condition in Future::AsyncAwait and this optimization in mojo might have just revealed it by getting rid of an intermediate promise that masked it, therefore I'm tagging in @leonerd too

Reference the optimization made in #1987 which is basically all that the 9.28 release contained