File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ sub query {
107107
108108 # Non-blocking
109109 $self -> {waiting } = {cb => $cb , sth => $sth };
110+ $self -> {finish } = [];
110111 $self -> _watch;
111112}
112113
@@ -134,6 +135,12 @@ sub unlisten {
134135 return $self ;
135136}
136137
138+ sub _finish_when_safe {
139+ my $self = shift ;
140+ if ($self -> {finish }) { push @{$self -> {finish }}, @_ }
141+ else { $_ -> finish for @_ }
142+ }
143+
137144sub _notifications {
138145 my $self = shift ;
139146
@@ -178,6 +185,7 @@ sub _watch {
178185 my $err = defined $result ? undef : $dbh -> errstr;
179186
180187 $self -> $cb ($err , $self -> results_class-> new(db => $self , sth => $sth ));
188+ $self -> _finish_when_safe(@{delete $self -> {finish }}) if $self -> {finish };
181189 $self -> _unwatch unless $self -> {waiting } || $self -> is_listening;
182190 }
183191 )-> watch($self -> {handle }, 1, 0);
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ has [qw(db sth)];
1010sub DESTROY {
1111 my $self = shift ;
1212 return unless my $sth = $self -> {sth };
13- $sth -> finish unless --$sth -> {private_mojo_results };
13+ $self -> finish unless --$sth -> {private_mojo_results };
1414}
1515
1616sub array { ($_ [0]-> _expand($_ [0]-> sth-> fetchrow_arrayref))[0] }
@@ -23,7 +23,7 @@ sub hash { ($_[0]->_expand($_[0]->sth->fetchrow_hashref))[0] }
2323
2424sub expand { ++$_ [0]{expand } and return $_ [0] }
2525
26- sub finish { shift -> sth -> finish }
26+ sub finish { $_ [0] -> db -> _finish_when_safe( $_ [0] -> sth) }
2727
2828sub hashes { _collect($_ [0]-> _expand(@{$_ [0]-> sth-> fetchall_arrayref({})})) }
2929
You can’t perform that action at this time.
0 commit comments