I have an array of devices.
For each device I want to set the default name ("DeviceX" - X its a sequence number) but some of them might be already used/occupied. So I need make an request to check if name already exists (ifDeviceExists() returns true or false in response). If the name is already occupied it should increase the number and once again send request to check if that name (e.g. "Device2") already exist. If name is not occupied then it should set name of that device (device.name = "Device2").
For example - occupied devices names: "Device2" and "Device4". Then the names of new created devices should be: "Device1", "Device3", "Device5", "Device6" ...
So the devices array should be: [{name: "Device1"}, {name: "Device3"}, {name: "Device5"}, {name: "Device6"}, ... ]
The main problem for me here is that checking if name exists is async action and I do not know how to handle that (where to send request and when to subscribe) Could anyone help me with that?