Skip to content

Improve async callbacks handling in hooks #57

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

iNishant
Copy link

@iNishant iNishant commented Mar 25, 2025

Adds support for awaiting async callbacks in on-commit hooks

for eg in below code

class UserService {
    async enqueueSignUpEmail(user) {
      await queue.publish(....);
    }
  
    @Transactional
    async createUser(user) {
       const newUser = await this.repo.insert(user);

      // Some more business logic
 
      // No way to `await` the side effect earlier
      runOnTransactionCommit(() => this.enqueueSignUpEmail(user));

     // Some more business logic

    }
}

const newUser = await new UserService().createUser(...)
// At this point side-effects have been awaited as well

@Aliheym thoughts on this?

@iNishant iNishant marked this pull request as draft March 25, 2025 17:20
@iNishant iNishant marked this pull request as ready for review March 25, 2025 19:40
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.

1 participant