Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/Mango.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use Carp 'croak';
use Hash::Util::FieldHash;
use Mango::BSON 'bson_doc';
use Mango::Database;
use Mango::Promises;
use Mango::Protocol;
use Mojo::IOLoop;
use Mojo::URL;
Expand All @@ -13,6 +14,7 @@ use Scalar::Util 'weaken';

use constant DEBUG => $ENV{MANGO_DEBUG} || 0;
use constant DEFAULT_PORT => 27017;
use constant PROMISES => Mango::Promises::PROMISES;

has connect_opt => sub { [] };
has default_db => 'admin';
Expand All @@ -31,6 +33,8 @@ Hash::Util::FieldHash::fieldhash my %AUTH;

our $VERSION = '1.30';

Mango::Promises->generate_p_methods(qw(get_more kill_cursors/0 query));

sub DESTROY { shift->_cleanup }

sub backlog { scalar @{shift->{queue} || []} }
Expand Down Expand Up @@ -406,6 +410,13 @@ you can use to generate data types that are not available natively in Perl.
All connections will be reset automatically if a new process has been forked,
this allows multiple processes to share the same L<Mango> object safely.

Since version 1.31, L<Mango> supports non-blocking with promise-returning
methods like
L<< $collection->find_one_p|Mango::Collection/"find_one_p" >>,
L<< $cursor->all_p|Mango::Cursor/"all_p" >>,
L<< $bulk->execute_p|Mango::Bulk/"execute_p" >>, etc.
Note that promise support depends on L<Mojo::Promise> (L<Mojolicious> 7.53+).

For better scalability (epoll, kqueue) and to provide IPv6, SOCKS5 as well as
TLS support, the optional modules L<EV> (4.0+), L<IO::Socket::IP> (0.20+),
L<IO::Socket::Socks> (0.64+) and L<IO::Socket::SSL> (1.84+) will be used
Expand Down Expand Up @@ -554,6 +565,15 @@ perform operation non-blocking.
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

=head2 get_more_p

my $promise = $mango->get_more_p($namespace, $return, $cursor);

Same as L</"get_more">, but performs a non-blocking operation
and returns a L<Mojo::Promise> object instead of accepting a callback.

Notice that promise support depends on L<Mojo::Promise> (L<Mojolicious> 7.53+).

=head2 kill_cursors

$mango->kill_cursors(@ids);
Expand All @@ -567,6 +587,15 @@ perform operation non-blocking.
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

=head2 kill_cursors_p

my $promise = $mango->kill_cursors_p(@ids);

Same as L</"kill_cursors">, but performs a non-blocking operation
and returns a L<Mojo::Promise> object instead of accepting a callback.

Notice that promise support depends on L<Mojo::Promise> (L<Mojolicious> 7.53+).

=head2 new

my $mango = Mango->new;
Expand Down Expand Up @@ -607,6 +636,16 @@ perform operation non-blocking.
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

=head2 query_p

my $promise
= $mango->query_p($namespace, $flags, $skip, $return, $query, $fields);

Same as L</"query">, but performs a non-blocking operation
and returns a L<Mojo::Promise> object instead of accepting a callback.

Notice that promise support depends on L<Mojo::Promise> (L<Mojolicious> 7.53+).

=head1 DEBUGGING

You can set the C<MANGO_DEBUG> environment variable to get some advanced
Expand Down
12 changes: 12 additions & 0 deletions lib/Mango/Bulk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use Mojo::Base -base;

use Carp 'croak';
use Mango::BSON qw(bson_doc bson_encode bson_oid bson_raw);
use Mango::Promises;
use Mojo::IOLoop;

has 'collection';
has ordered => 1;

Mango::Promises->generate_p_methods(qw(execute));

sub execute {
my ($self, $cb) = @_;

Expand Down Expand Up @@ -209,6 +212,15 @@ non-blocking.
});
Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

=head2 execute_p

my $promise = $bulk->execute_p;

Same as L</"execute">, but performs bulk operations non-blocking
and returns a L<Mojo::Promise> object instead of accepting a callback.

Notice that promise support depends on L<Mojo::Promise> (L<Mojolicious> 7.53+).

=head2 find

$bulk = $bulk->find({foo => 'bar'});
Expand Down
Loading