Return a value from an async event emmiter in nestjs

39 views Asked by At

I have an event emitter

@OnEvent(ANALYSIS_CREATED_EVENT, { async: true })
  async handleAnalysisCreatedEvent(event: AnalysisCreatedEvent) {
    this.logger.debug('Processing AnalysisCreatedEvent...');
    const { createAnalysisDto, analysisId, results, hash, analysisName, authContext, backtested } = event;

    const savedAnalysis = await this.analysesRepository.create({
      createdBy: authContext.by,
      updatedAs: authContext.as,
      updatedBy: authContext.by,
      ownerId: authContext.as,
    });

    const resultData = { id: analysisId, results, backtested };

return savedAnalysis.id
  }

I then call the eventEmitter in another file

const res = await this.eventEmitter.emitAsync(ANALYSIS_CREATED_EVENT, analysisCreatedEvent);
    console.log('the result from the event emitter is ************', res)

however the result I get is

the result from the event emitter is ************ [
  Immediate {
    _idleNext: null,
    _idlePrev: null,
    _onImmediate: [Function (anonymous)],
    _argv: undefined,
    _destroyed: false,
    [Symbol(refed)]: true,
    [Symbol(asyncId)]: 30080,
    [Symbol(triggerId)]: 29827,
    [Symbol(kResourceStore)]: Store { logger: [EventEmitter] }
  }
]

What am i doing wrong? When i remove the { async: true } I get the correct data, but i do not want to remove it as the function is async. How can i solve this?

0

There are 0 answers