Skip to content

Commit

Permalink
consistently calling runs callback, with tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
njlg committed Sep 21, 2015
1 parent 8a5890e commit 363f0af
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Rethinkdb/IO.pm
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ sub _send {
say {*STDERR} Dumper $res;
}

# if there is callback return data to that
if ( $self->_callbacks->{$token} ) {
my $cb = $self->_callbacks->{$token};
delete $self->_callbacks->{$token};
return $cb->($res);
}

return $res;
}

Expand Down
14 changes: 14 additions & 0 deletions t/connect.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ eval { r->connect( 'localhost', 28015, 'better', 'hiddenkey' ); } or do {
my $r = r->connect( 'localhost', 28015, 'better', '', 100 );
is $r->timeout, 100, 'Correct timeout set';

# query without connection should throw an error
eval { r->db('test')->create->run; } or do {
like $@, qr/ERROR: run\(\) was not given a connection/,
'Correct error on `run` without connection';
};

# internal stuff
r->connect;
is r->io, undef;
Expand Down Expand Up @@ -149,6 +155,14 @@ r->db('test')->table('battle')->run({array_limit => 2});
$res = r->db('test')->table('battle')->run({noreply => 1});
is $res, undef, 'Correct response for noreply';

# test a callback
$res = r->db('test')->table('battle')->run(sub {
my $res = shift;
isa_ok $res, 'Rethinkdb::Response', 'Correct response for callback';
});

isa_ok $res, 'Rethinkdb::Response', 'Correct response for callback return';

# clean up
r->db('test')->drop->run;

Expand Down

0 comments on commit 363f0af

Please sign in to comment.