In my OrderServer class, I am utilizing an OrderService to connect to a database and retrieve data every minute. The communication with the web app is handled through SocketIO. Here is a snippet of the code:
export class OrderServer {
// some required fields
constructor() {
console.log("Initializing OrderServer...");
this._orderService = new OrderService();
// additional setup
this.listen();
}
private listen(): void {
this.server.listen(this.port, () => {
});
this.io.on('connect', (socket: socketIo.Socket) => {
setInterval(() => {
let orders : Order[] = this._orderService.getNewNProcessingOrders();
console.log("Orders : " + orders);
}, 60000);
});
}
}
I have the code for OrderService as well but it's not necessary to include it at the moment. If needed, I can provide it later.
The issue arises with the ordering of console log statements in the getNewNProcessingOrders() method. Despite calling getNewNProcessingOrders() first in the listen method, the corresponding console log statement executes after the one in listen(). This raises the question of why this call is non-blocking. I've searched for documentation on this matter without success, specifically dealing with scenarios where service method calls are non-blocking.