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

io.magentys.java8.FutureMission Maven / Gradle / Ivy

The newest version!
package io.magentys.java8;

import io.magentys.Mission;

import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

public interface FutureMission extends Mission {

    default CompletableFuture accomplishAsync(Mission mission, FunctionalAgent agent) {
            CompletableFuture futureResult = new CompletableFuture<>();
            Runnable runnable = () -> {
                try {
                    Result result = mission.accomplishAs(agent);
                    futureResult.complete(result);
                } catch (Throwable e) {
                    futureResult.completeExceptionally(e);
                }
            };
            new Thread(runnable).start();

            return futureResult;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy