Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Promise.await when calling before and after methods #19

Open
antislash21 opened this issue Apr 26, 2024 · 1 comment
Open

Use Promise.await when calling before and after methods #19

antislash21 opened this issue Apr 26, 2024 · 1 comment

Comments

@antislash21
Copy link

I use meteor hooks to perform calls to external APIs (to synchronise groups between my Meteor app and external apps).
The methods I pass to afterMethod are asynchronous, but when they are called, my app does not await for them to finish.

This results in incoherencies when i perform several actions one after another. For example:

  • create a group
  • assign users to this group

the second call fails because it tries to assign users before the group is actually created in the external application.

The only way I found for solving this problem is to modify server.js in order to wrap before/after functions calls with Promise.await :

    for (const beforeFn of beforeFns) {
      if (Promise.await(beforeFn.apply(this, args)) === false) {
        return false;
      }
    }

....

    for (const afterFn of afterFns) {
      try { Promise.await(afterFn.apply(this, args)); } catch (error) { /* */ }
    }

Is it possible to integrate these changes to this repository to avoid making a fork ?

Thanks for your time

Copy link

Thank you for submitting this issue!

We, the Members of Meteor Community Packages take every issue seriously.
Our goal is to provide long-term lifecycles for packages and keep up
with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.

However, we contribute to these packages mostly in our free time.
Therefore, we can't guarantee your issues to be solved within certain time.

If you think this issue is trivial to solve, don't hesitate to submit
a pull request, too! We will accompany you in the process with reviews and hints
on how to get development set up.

Please also consider sponsoring the maintainers of the package.
If you don't know who is currently maintaining this package, just leave a comment
and we'll let you know

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

No branches or pull requests

1 participant