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

io.machinecode.then.core.RunnableDeferred Maven / Gradle / Ivy

package io.machinecode.then.core;

import io.machinecode.then.api.ExecutablePromise;
import io.machinecode.then.api.Promise;

import java.util.concurrent.Callable;

/**
 * @author Brent Douglas
 * @since 1.0
 */
public class RunnableDeferred extends DeferredImpl implements ExecutablePromise, Promise, Callable, Runnable {

    protected final Runnable call;
    protected final T value;

    public RunnableDeferred(final Runnable call, final T value) {
        this.call = call;
        this.value = value;
    }

    @Override
    public void run() {
        try {
            call.run();
        } catch (final Throwable e) {
            reject(e);
            return;
        }
        resolve(value);
    }

    @Override
    public T call() throws Exception {
        run();
        return get();
    }

    @Override
    public Runnable asRunnable() {
        return this;
    }

    @Override
    public Callable asCallable() {
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy