Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

369
Views
Using Async Event Listener with Nestjs EventEmitter Module and Serverless functions

I'm trying to implement an asynchronous worker with serverless lambda function with help of nestjs EventEmitter module.

Handler is getting invoked on emitting an event, but the function gets closed before the async / await call.

I have tried using both emit and emitAsync functions and different arguments for @OnEvent(AccountEvents.NEW_ACCOUNT, {async:true, promisify:true})

Producer Snippet

  public async execute(event: EventDetail): Promise<void> {

    await this.eventEmitter.emitAsync(AccountEvents.NEW_ACCOUNT, event);
  }

Listener Snippet

@OnEvent(AccountEvents.NEW_ACCOUNT)
  public async handleAccountCreatedEvent(event: EventDetail): Promise<void> {
    this.logger.log({ message: `Log1: ${AccountEvents.NEW_ACCOUNT} Handler`, event });
    const message = await this.testAsync();
    this.logger.log({ message });
    this.logger.log({ message: 'Log 3: Event Processing Successfuly Completed' });
  }

  private testAsync(): Promise<string> {
    return new Promise(res => {
      setTimeout(() => {
        res('Log 2: Promise resolved after one sec');
      }, 1000);
    });
  }

Expect Output : all the 3 log statements Actual Output : only first log statement (Log1)

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!