Yes, you right. May be need to do truncate table qwe at least and delete 
"$delay->pass;" line to reduce number of lines in main logic.

вторник, 24 марта 2015 г., 19:52:13 UTC+5 пользователь Dotan Dimet написал:
>
>  There's a $delay->pass at the 2nd line of the 2nd step, which I think 
> will cause it to skip right down to the 3rd step?
>
> On 03/24/2015 04:01 PM, Dan Book wrote:
>  
> That is not correct. The callback from $delay->begin is intended to be 
> invoked when the non-blocking activity is ready, after the control has 
> returned to the event loop.
>
> On Tue, Mar 24, 2015 at 9:57 AM, Daniel Mantovani <[email protected] 
> <javascript:>> wrote:
>
>> In Mojo::IOLoop either $delay->begin or $delay->end must be invoked 
>> BEFORE you leave each step. It doesn't seem to be the case in the first 
>> step. 
>>
>>  There is a very nice explanation of what is hapening here: 
>> http://www.slideshare.net/deepfountainconsulting/asynchronous-programming-patterns-in-perl.
>>  
>> There is even a very similar case in the quiz # 1, page 91. Just writing 
>> $delay->begin inside a callback does not mean you are actually invoking it 
>> before you leave the step.
>>  
>>  Second step looks fine, I tried but couldn't actually make it work :( 
>> but hope this comment will help.
>>
>>  BR,
>> Daniel
>>
>> El martes, 24 de marzo de 2015, 1:34:11 (UTC-3), Alexey Stavrov escribió: 
>>  
>>> I have this code which not output "666", "End Inserts", "End". What i do 
>>> wrong? 
>>>
>>>   #!/usr/bin/perl
>>>
>>>
>>> use strict;
>>> use warnings;
>>> use v5.10;
>>>
>>>
>>> use Mojo::Pg;
>>> use Mojo::IOLoop;
>>>
>>>
>>> my $pg = Mojo::Pg->new('postgresql://alex@/test');
>>>
>>>
>>> my $db = $pg->db;
>>>
>>>
>>> $db->query(q{create table if not exists qwe (num integer, text text)});
>>>
>>>
>>> sub upsert {
>>>   Mojo::IOLoop->delay(
>>>     sub {
>>>       my $delay = shift;
>>>       for my $i (1 .. 30) {
>>>         warn "update: $i";
>>>         $db->query(q{update qwe set num = ? where text = ?}, $i, "$i" => 
>>> $delay->begin);
>>>       }
>>>     },
>>>     sub {
>>>       my $delay = shift;
>>>
>>>
>>>       $delay->pass;
>>>
>>>
>>>       for my $i (1 .. 30) {
>>>         my ($err, $res) = (shift, shift);
>>>         unless ($res->rows) {
>>>           my $end = $delay->begin;
>>>           say "insert $i";
>>>           $db->query(q{insert into qwe(num, text) values (?, ?)}, $i, 
>>> "$i" => sub { say '666'; $end->(@_); });
>>>         }
>>>       }
>>>     },
>>>     sub {
>>>       say 'End inserts';
>>>       Mojo::IOLoop->stop;
>>>     }
>>>   );
>>> }
>>>
>>>
>>> upsert();
>>>
>>>
>>> Mojo::IOLoop->start;
>>>
>>>
>>> say 'End';
>>>
>>>  
>>>
>>>  Thanks.
>>>  
>>     -- 
>> 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 [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/mojolicious.
>> For more options, visit https://groups.google.com/d/optout.
>>  
>  
>  -- 
> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected] 
> <javascript:>.
> Visit this group at http://groups.google.com/group/mojolicious.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
> -- 
> This message has been scanned for viruses and 
> dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is 
> believed to be clean. 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to