Minor refinements
diff --git a/lib/Korap/API.pm b/lib/Korap/API.pm
index 70ec277..01bda48 100644
--- a/lib/Korap/API.pm
+++ b/lib/Korap/API.pm
@@ -1,6 +1,6 @@
package Korap::API;
use Mojo::Base 'Mojolicious::Plugin';
-use Scalar::Util 'blessed';
+use Scalar::Util qw/blessed weaken/;
use strict;
use warnings;
@@ -91,6 +91,7 @@
$url => sub {
my $tx = pop;
$self->_process_response('matches', $index, $tx);
+ weaken $index;
return $cb->($index);
});
}
@@ -135,6 +136,7 @@
# non-blocking
if ($cb) {
+ weaken $index;
# Trace non-blocking
$ua->start(
@@ -188,6 +190,7 @@
# non-blocking
if ($cb) {
+ weaken $index;
$ua->get(
$url => sub {
my $tx = pop;
@@ -242,6 +245,7 @@
$ua->inactivity_timeout(30);
if ($cb) {
+ weaken $index;
$ua->get(
$url => sub {
$self->_process_response('resource', $index, pop);