I have a task that runs asynchronously and takes a long time to complete. When the task starts, I display a mat-spinner with a timeout set at 60000 milliseconds. However, we now have a notification service that provides updates on the job status. I would like to stop the spinner when a message is received, regardless of whether the job was successful or not.
Code for displaying a spinner with a timeout:-
this.recommendationService
.executeCustomerOpportunityMapper(opportuniyMapperJson)
.subscribe(
response => {
this.isExecuteOppRanking = true;
this.snakbar.statusBar(
"Executing customer opportunity ranking",
"Success"
);
this.spinner.show();
setTimeout(() => {
this.spinner.hide();
this.loadRankedOpportunities(tableMetadata);
this.selectedIndex = 3;
this.isExecuteOppRanking = false;
}, 60000);
Message Notification Service:-
this.messageService.messageReceived$.subscribe(data => {
this.snakbar.statusBar("Platform job status - " + data, "Info");
});
I want the spinner to stop when the messageService receives a success/failure notification instead of waiting for the 60000 ms timeout.