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

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

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

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

public class DeferredTaskRunner {
    private final AtomicBoolean condition;
    private final List deferredTasks;
    public DeferredTaskRunner() {
        this.condition = new AtomicBoolean(false);
        this.deferredTasks = new ArrayList<>();
    }

    public void execute() {
        condition.set(true);
        deferredTasks.forEach(Runnable::run);
        deferredTasks.clear();
    }

    public void schedule(Runnable runnable){
        if(condition.get()){
            runnable.run();
            return;
        }

        deferredTasks.add(runnable);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy