All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.voox.graphql.IDataLoader Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package cc.voox.graphql;

import org.dataloader.DataLoader;
import org.dataloader.Try;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

public interface IDataLoader {
    default DataLoader get() {
        return DataLoader.newDataLoader(keys -> CompletableFuture.supplyAsync(() -> handle(keys)));
    }

    default DataLoader getTry() {
        return DataLoader.newDataLoaderWithTry(keys -> CompletableFuture.supplyAsync(() -> handleTry(keys)));
    }

    default List> handleTry(List keys) {
        return keys.stream().map(k -> handleTry(k)).collect(Collectors.toList());
    }

    default  Try handleTry(K k) {
        return Try.tryCall(() -> handle(k));
    }

    List handle(List keys);
    V handle(K key);

    default boolean useTryMode() {
        return false;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy