se.michaelthelin.spotify.SpotifyApiThreading Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotify-web-api-java Show documentation
Show all versions of spotify-web-api-java Show documentation
A Java client for Spotify's Web API
package se.michaelthelin.spotify;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class SpotifyApiThreading {
public static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool();
public static CompletableFuture executeAsync(final Callable callable) {
CompletableFuture future = new CompletableFuture<>();
SpotifyApiThreading.THREAD_POOL.execute(() -> {
try {
future.complete(callable.call());
} catch (Exception e) {
future.completeExceptionally(e);
}
});
return future;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy