it.auties.whatsapp.util.OrderedAsyncTaskRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of whatsappweb4j Show documentation
Show all versions of whatsappweb4j Show documentation
Standalone fully-featured Whatsapp Web API for Java and Kotlin
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);
}
}