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

it.auties.whatsapp.util.OrderedAsyncTaskRunner Maven / Gradle / Ivy

There is a newer version: 2.7.2
Show newest version
package it.auties.whatsapp.util;

import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

public class OrderedAsyncTaskRunner {
    private CompletableFuture lastFuture;

    public  CompletableFuture runAsync(Supplier> future){
        var result = lastFuture == null ? future.get() : lastFuture.thenComposeAsync(ignored -> future.get());
        this.lastFuture = result;
        return result;
    }

    public void cancel(){
        if(lastFuture == null){
            return;
        }
        lastFuture.cancel(true);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy