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

com.twilio.base.Fetcher Maven / Gradle / Ivy

There is a newer version: 10.6.3
Show newest version
package com.twilio.base;

import com.twilio.Twilio;
import com.twilio.http.TwilioRestClient;

import java.util.concurrent.CompletableFuture;

/**
 * Executor for fetches of a resource.
 *
 * @param  type of the resource
 */
public abstract class Fetcher {

    /**
     * Execute an async request using default client.
     *
     * @return future that resolves to requested object
     */
    public CompletableFuture fetchAsync() {
        return fetchAsync(Twilio.getRestClient());
    }

    /**
     * Execute an async request using specified client.
     *
     * @param client client used to make request
     * @return future that resolves to requested object
     */
    public CompletableFuture fetchAsync(final TwilioRestClient client) {
        return CompletableFuture.supplyAsync(() -> fetch(client), Twilio.getExecutorService());
    }

    /**
     * Execute a request using default client.
     *
     * @return Requested object
     */
    public T fetch() {
        return fetch(Twilio.getRestClient());
    }

    /**
     * Execute a request using specified client.
     *
     * @param client client used to make request
     * @return Requested object
     */
    public abstract T fetch(final TwilioRestClient client);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy