package cn.axzo.msg.center.utils;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;

/**
 * @author yanglin
 */
public class AsyncRunTasks extends AsyncTasks<Void> {

    private final ExecutorService executor;

    /**
     * use common pool
     */
    public AsyncRunTasks() {
        this(null);
    }

    public AsyncRunTasks(ExecutorService executor) {
        this.executor = executor;
    }

    public void runAsync(Runnable runnable) {
        CompletableFuture<Void> future = executor == null
                ? CompletableFuture.runAsync(runnable)
                : CompletableFuture.runAsync(runnable, executor);
        add(future);
    }

}