michelmartin...@yahoo.com Le jeudi 5 août 2021 à 17:39:01 UTC+2, Vincent Tondellier a écrit :
> Hi, > > > On 2021-08-04, 11:30:43 CEST Dingbing Liw wrote: > > I am refactoring my mojolicious app. > > Is there any way to use promise and keep the same return value? > > You can use async/await for this. > > See > https://metacpan.org/dist/Mojolicious/view/lib/Mojolicious/Guides/Cookbook.pod#async/await > > Your example would be: > sub some_method { > my $a = block_function_a(); > my $b = block_function_b(); > my $c = await nonblock_function_c(); > return $a+$b+$c; > } > > where nonblock_function_c can either return a promise or be an async > function (see doc) > > > > > For example: > > > > My original method: > > sub some_method { > > my $a = block_function_a(); > > my $b = block_function_b(); > > my $c = block_function_c(); ### for example many Mojo::Pg search > > return $a+$b+$c; > > } > > > > Now I change block_function_c to an unblocked promise. > > > > sub some_method { > > my $a = block_function_a(); > > my $b = block_function_b(); > > return promise_mojo_db_search->then(sub($c){ > > $a+$b+c; > > } > > ); > > } > > > > I have to change many relative code after the return value change. > > It is very annoying. > > Is there any way to return the same value with promise. > > > > > -- You received this message because you are subscribed to the Google Groups "Mojolicious" group. To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/mojolicious/e0db0c2a-dfb1-4bdb-bd46-7805441be530n%40googlegroups.com.