package speiger.src.coreengine.assets.base;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

public abstract class SteppedReloadableAsset<T> implements IReloadableAsset {
	@Override
	public final CompletableFuture<Void> reloadAssets(IAssetProvider provider, IReloadSyncer syncer, Executor offthreadExectutor, Executor syncExecutor) {
		return CompletableFuture.supplyAsync(() -> prepare(provider), offthreadExectutor).thenCompose(syncer::sync).thenAcceptAsync(T -> apply(T, provider), syncExecutor);
	}
	
	protected abstract T prepare(IAssetProvider provider);
	protected abstract void apply(T value, IAssetProvider provider);
}
