Skip to content

Conversation

@aferreira
Copy link

This pull request adds promise-returning methods to Mango and related classes as an alternative to non-blocking with callbacks. For this, it relies on Mojo::Promise as introduced with Mojolicious 7.53.

All of Mango continues to work with older Mojolicious as it used to. Only, if Mojo::Promise is not available, the new methods, like $collection->find_one_p and $bulk->execute_p, don't do anything but to throw exceptions like:

find_one_p() requires Mojo::Promise

In the same vein, tests cover the new methods if Mojo::Promise is available and, if not, the corresponding tests are ignored.

Most of the patch is repetitive documentation and the new tests. The code change is small, consisting of a new (internal) helper class Mango::Promises that generate the _p methods from the original methods (like Mango::Bulk::execute_p from Mango::Bulk::execute) and the inclusion of code like below to each class

package Mango::Collection;
...
use Mango::Promises;
...
Mango::Promises->generate_p_methods(
  qw(aggregate create/0 drop/0 drop_index/0 ensure_index/0 find_and_modify find_one
    index_information insert map_reduce options remove rename save stats update)
);

@aferreira
Copy link
Author

@oliwer Let me know what you think about this patch.

@oliwer
Copy link
Owner

oliwer commented Sep 5, 2018

From a quick first look this looks very good! I'd like to test it a bit more before merging. I'll comment back soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants