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

se.michaelthelin.spotify.SpotifyApiThreading Maven / Gradle / Ivy

There is a newer version: 9.0.0-RC1
Show newest version
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