Use CompletableFuture
when saving
This commit is contained in:
parent
e8b7bf07b8
commit
857807aca1
1 changed files with 34 additions and 28 deletions
|
@ -48,23 +48,32 @@ public abstract class RegistriesDataProvider implements DataProvider {
|
||||||
|
|
||||||
return registriesFuture.thenCompose(registriesProvider -> CompletableFuture
|
return registriesFuture.thenCompose(registriesProvider -> CompletableFuture
|
||||||
.supplyAsync(() -> registries)
|
.supplyAsync(() -> registries)
|
||||||
.thenCompose(entries -> CompletableFuture.runAsync(() -> {
|
.thenCompose(entries -> {
|
||||||
registries.acquireLock();
|
registries.acquireLock();
|
||||||
final RegistryOps<JsonElement> dynamicOps = RegistryOps.create(
|
final RegistryOps<JsonElement> dynamicOps = RegistryOps.create(
|
||||||
JsonOps.INSTANCE,
|
JsonOps.INSTANCE,
|
||||||
registriesProvider
|
registriesProvider
|
||||||
);
|
);
|
||||||
|
|
||||||
for (RegistrySupplier.RegistryInfo<?> registryData : entries.allRegistries) {
|
CompletableFuture<?>[] futures = entries
|
||||||
serializeRegistry(
|
.allRegistries
|
||||||
cachedOutput, registriesProvider, dynamicOps, registryData
|
.stream()
|
||||||
);
|
.map(registryData -> serializeRegistry(
|
||||||
}
|
cachedOutput,
|
||||||
registries.releaseLock();
|
registriesProvider,
|
||||||
})));
|
dynamicOps,
|
||||||
|
registryData
|
||||||
|
))
|
||||||
|
.toArray(CompletableFuture<?>[]::new);
|
||||||
|
|
||||||
|
registries.releaseLock();
|
||||||
|
return CompletableFuture.allOf(futures);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void serializeRegistry(
|
private <T> CompletableFuture<?> serializeRegistry(
|
||||||
CachedOutput cachedOutput,
|
CachedOutput cachedOutput,
|
||||||
HolderLookup.Provider registryAccess,
|
HolderLookup.Provider registryAccess,
|
||||||
DynamicOps<JsonElement> dynamicOps,
|
DynamicOps<JsonElement> dynamicOps,
|
||||||
|
@ -86,19 +95,18 @@ public abstract class RegistriesDataProvider implements DataProvider {
|
||||||
registryData.key().location().getPath()
|
registryData.key().location().getPath()
|
||||||
);
|
);
|
||||||
|
|
||||||
elements.forEach(entry ->
|
return CompletableFuture.allOf(elements.stream().map(entry -> serializeElements(
|
||||||
serializeElements(
|
pathProvider.json(entry.unwrapKey().orElseThrow().location()),
|
||||||
pathProvider.json(entry.unwrapKey().orElseThrow().location()),
|
cachedOutput,
|
||||||
cachedOutput,
|
dynamicOps,
|
||||||
dynamicOps,
|
registryData.elementCodec(),
|
||||||
registryData.elementCodec(),
|
entry.value()
|
||||||
entry.value()
|
)).toArray(CompletableFuture[]::new));
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <E> void serializeElements(
|
private <E> CompletableFuture<?> serializeElements(
|
||||||
Path path,
|
Path path,
|
||||||
CachedOutput cachedOutput,
|
CachedOutput cachedOutput,
|
||||||
DynamicOps<JsonElement> dynamicOps,
|
DynamicOps<JsonElement> dynamicOps,
|
||||||
|
@ -112,11 +120,9 @@ public abstract class RegistriesDataProvider implements DataProvider {
|
||||||
string
|
string
|
||||||
));
|
));
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
DataProvider.saveStable(cachedOutput, optional.get(), path);
|
return DataProvider.saveStable(cachedOutput, optional.get(), path);
|
||||||
LOGGER.info(path + " written");
|
|
||||||
} else {
|
|
||||||
LOGGER.warning(path + " is empty");
|
|
||||||
}
|
}
|
||||||
|
return CompletableFuture.completedFuture(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildRegistry(RegistrySetBuilder registryBuilder) {
|
public void buildRegistry(RegistrySetBuilder registryBuilder) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue