Meteor-Community-Packages / Meteor-Community-Packages/meteor-method-hooks
Use Promise.await when calling before and after methods
- Dominant language
- JavaScript
- Stars
- 26
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
Research direction
Start in server.js, where the before and after hook functions are invoked, and inspect how asynchronous return values are currently handled. Verify the hook sequence with asynchronous callbacks and ensure later operations wait for completion while preserving the existing false-return and error-handling behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100