mojolicious / mojo-pg

Mojolicious :heart: PostgreSQL
https://metacpan.org/release/Mojo-Pg
Artistic License 2.0
101 stars 46 forks source link

Emit error event in case of asynchronous operation. #24

Closed kak-tus closed 8 years ago

kak-tus commented 8 years ago

Summary

User can subscribe on error event, but in case of error in asynchronous operation it can't emitted.

Use case: If we using many asynchronous functions with different requests, we must check and log error in any function.

sub sub1 {
  $pg->db->query('select 1', sub {
    my ( $db, $error, $results ) = @_;

    if ($error) {
      $logger->error($error);
    }
  } );
}

sub sub2 {
  $pg->db->query('select 2', sub {
    my ( $db, $error, $results ) = @_;

    if ($error) {
      $logger->error($error);
    }
  } );
}

In case of error emitting we can have one global callback to log errors

$pg->on(
  error => sub {
    my ( $e, $err ) = @_;
    $logger->error($err);
  }
);

References

No.

kraih commented 8 years ago

Sorry, but the use case doesn't convince me, and the behavior is inconsistent with other modules like Mojo::UserAgent. 👎

kraih commented 8 years ago

Thanks for your contribution, but i'm afraid this pull request did not pass the vote.