Interface Queueable<T,R extends QResponse>

Type Parameters:
T - Type of the data that should be retrieved / the result of the Task
All Superinterfaces:
ExecutableTask<T,R>, HasAsyncManager, HasAsyncQueue<R>, Task<T,R>
All Known Implementing Classes:
QueueableBase

public interface Queueable<T,R extends QResponse> extends ExecutableTask<T,R>, HasAsyncManager, HasAsyncQueue<R>

A Queueable is special ExecutableTask, that can be queued and executed. Unlike other Tasks, a Queueable will actually end up in some kind of queue after being queued.

By invoking Task.queue(), a Future will be created and queued. queueing order and simultaneous task count may depend on the specific implementation of the used AsyncQueue.

The result can be processed by using listeners like Future.then(ResultConsumer). These can be set directly when queuing by calling Task.queue(ResultConsumer). These listeners may be called from the thread used by the queue. That is why Object.wait(), Thread.sleep(long) or any other blocking tasks may never be called inside these listeners!. This may delay the queue and could lead to deadlocks.


Example Queueable usage:

 //Retrieve a Message...
 //This creates a Queueable
 var msgRetriever = lApi.getRequestFactory()
                        .getChannelMessage("channelId", "messageId");

 //Queue and create a listener
 //This creates a Future
 msgRetriever.queue((result, response, error) -> {
             if(error != null) {
                 System.out.println("could not get message.");
                 return;
             }

             System.out.println("Message content: " + result.getContent());

         });
 
See Also: