Before, it was possible to load parking lot data multiple times due to race conditions. If we had >1 event triggering a map load, then we'd have two requests concurrently.
We need a thread-safe way to only load the data once, i.e. something that keeps track of in-flight requests. We can do that with a Map<CityId, Promise>, which makes sure we never have more than one Promise for a given city. Once the Promise is complete, we then add the city to ParkingLotLoader.loadedCities.
Before, it was possible to load parking lot data multiple times due to race conditions. If we had >1 event triggering a map load, then we'd have two requests concurrently.
We need a thread-safe way to only load the data once, i.e. something that keeps track of in-flight requests. We can do that with a
Map<CityId, Promise>
, which makes sure we never have more than onePromise
for a given city. Once the Promise is complete, we then add the city toParkingLotLoader.loadedCities
.