Skip to content

Commit

Permalink
Start implementing Promises
Browse files Browse the repository at this point in the history
  • Loading branch information
SPodjasek committed Dec 22, 2017
1 parent 801d367 commit 6837904
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Changes
@@ -1,5 +1,8 @@
{{$NEXT}}

- Start implementing Mojo::Promise, drop support for Mojolicious <7.53
- Implement DEBUG on Client as suggested in #11
- Fix query parameter naming in Publisher
- Fix missing imports in Publisher #15
0.0.9 2017-02-18T11:07:56Z
- Proper implementation of URI parser PR#8 & #9
- Support for query parameter with aliases
Expand Down
2 changes: 1 addition & 1 deletion cpanfile
@@ -1,5 +1,5 @@
requires 'perl', '5.010';
requires 'Mojolicious', '6.10';
requires 'Mojolicious', '7.53';
requires 'Net::AMQP', '0.06';
requires 'File::ShareDir';
requires 'List::Util', '1.33';
Expand Down
71 changes: 71 additions & 0 deletions lib/Mojo/RabbitMQ/Client/Channel.pm
@@ -1,5 +1,6 @@
package Mojo::RabbitMQ::Client::Channel;
use Mojo::Base 'Mojo::EventEmitter';
use Mojo::Promise;

use Mojo::RabbitMQ::Client::LocalQueue;
use Mojo::RabbitMQ::Client::Method;
Expand Down Expand Up @@ -195,6 +196,16 @@ sub declare_exchange {
);
}

sub declare_exchange_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->declare_exchange(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub delete_exchange {
my $self = shift;

Expand All @@ -209,6 +220,16 @@ sub delete_exchange {
);
}

sub delete_exchange_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->delete_exchange(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub declare_queue {
my $self = shift;

Expand All @@ -228,6 +249,16 @@ sub declare_queue {
);
}

sub declare_queue_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->declare_queue(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub bind_queue {
my $self = shift;

Expand All @@ -241,6 +272,16 @@ sub bind_queue {
);
}

sub bind_queue_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->bind_queue(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub unbind_queue {
my $self = shift;

Expand All @@ -253,6 +294,16 @@ sub unbind_queue {
);
}

sub unbind_queue_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->unbind_queue(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub purge_queue {
my $self = shift;

Expand All @@ -266,6 +317,16 @@ sub purge_queue {
);
}

sub purge_queue_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->purge_queue(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub delete_queue {
my $self = shift;

Expand All @@ -281,6 +342,16 @@ sub delete_queue {
);
}

sub delete_queue_p {
my $self = shift;

my $promise = Mojo::Promise->new;
my $method = $self->delete_queue(@_);
$method->on('success' => sub { shift; $promise->resolve(@_) })
$method->on('error' => sub { shift; $promise->reject(@_) })
$method->deliver;
}

sub publish {
my $self = shift;

Expand Down

2 comments on commit 6837904

@kraih
Copy link
Contributor

@kraih kraih commented on 6837904 Jan 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to return the promises at the end of the _p methods.

@SPodjasek
Copy link
Member Author

@SPodjasek SPodjasek commented on 6837904 Jan 16, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.