My code is the below:
automaticAssignment() {
this.model.selectedSignals.sort((a, b) => a.senal.localeCompare(b.senal));
this.model.selectedSignals.forEach(signal => {
if (signal.status === Asignacion.ASIGNADA || signal.status === Asignacion.AUTO_YA_ASIGNADA) {
this.messageService.add({
severity: 'warn',
summary: i18next.t("assignment:automatic_assignment"),
detail: i18next.t("assignment:signal_already_assigned", { signal: signal.senal })
});
signal.status = Asignacion.AUTO_YA_ASIGNADA;
} else {
const channelAvailable = this.model.channelList.find((channelAux => channelAux.tipoIO === signal.tipo && !channelAux.bloqueado && !channelAux.senalId));
if (channelAvailable) {
this.http.put<any>(`${this.signalUrl}/${this.model.selectedProject.id}/assign`, null, {
params: new HttpParams()
.append('plcId', channelAvailable.id.toString())
.append('signalId', signal.id.toString())
.append('value', "true"),
}).pipe(
tap(// Code which change the parameter senalId of channel
)).subscribe(() => {});
} else {
this.messageService.add({
severity: 'error',
summary: i18next.t("assignment:automatic_assignment"),
detail: i18next.t("assignment:no_available_channel", { signal: signal.senal }),
});
signal.status = Asignacion.AUTO_NO_CANAL;
}
}
});
this.model.selectedChannels = [];
}
The problem I have is that if the array selectedSignals
has several channels, the http request always have the same parameter plcId
because the http-calls are asynchronous. I need that requests execute the code which is in the subscribe in sequence in order to the find
method returns different channels.
How can I make this? Maybe should I use an array to join all the request and use concat()?
Thank you in advance,