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].
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