A NestJS module that provides a Promise-based API for executing asynchronous operations
Exopromise converts promises running in the same instance into http requests and runs them. It aims for a more balanced resource usage on the host. Thus, the server load running in multi-instance mode or cluster mode will be rebalanced via the load balancer. It is suitable for bulk operations.
The problem of load distribution can be solved with multiple threads, but for systems running with a container and orchestration tool, using multiple threads will increase chaoticness and unpredictability. NodeJS is suitable for orchestration tools due to its single thread nature. Therefore, it is a useful method to manage promise structures by converting them into http requests.
Note: Not suitable for singleton systems.
Import ExopromiseModule into the AppModule;
import { ExopromiseModule } from 'exopromise';
@Module({
imports: [ExopromiseModule.register({ baseUrl: 'http://localhost:3000' })],
controllers: [AppController],
providers: [AppService]
})
export class AppModule {}After that, just add the Exopromise decorator to the async methods you want to use. That's all.
import { Injectable } from '@nestjs/common';
import { Exopromise } from 'exopromise';
@Injectable()
export class ExampleService {
@Exopromise() // <-- This decorator will handle the request and response automatically
async consumeMessage(/** you can use parameters */): Promise<any> {
/**
* do amazing things...
*/
return Promise.resolve();
}
}