
org.smallibs.concurrent.execution.impl.ExecutorImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hpas Show documentation
Show all versions of hpas Show documentation
Functional ADT And Asynchronous library in Java
/*
* HPAS
* https://github.com/d-plaindoux/hpas
*
* Copyright (c) 2016-2017 Didier Plaindoux
* Licensed under the LGPL2 license.
*/
package org.smallibs.concurrent.execution.impl;
import org.smallibs.concurrent.execution.Executor;
import org.smallibs.concurrent.promise.Promise;
import org.smallibs.concurrent.promise.impl.RunnablePromise;
import org.smallibs.data.Unit;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
/**
* Asynchronous execution media
*/
public final class ExecutorImpl implements Executor {
/**
* Underlying executor service
*/
private final ExecutorService executorService;
/**
* Constructor
*
* @param executorService The executor service used for asynchronous operation
*/
public ExecutorImpl(ExecutorService executorService) {
this.executorService = executorService;
}
@Override
public Promise async(Callable task) {
Objects.requireNonNull(task);
final RunnablePromise runnablePromise = new RunnablePromise<>(task);
this.executorService.execute(runnablePromise);
return runnablePromise;
}
@Override
public Promise async(RunnableWithError task) {
Objects.requireNonNull(task);
final RunnablePromise runnablePromise = new RunnablePromise<>(() -> {
task.run();
return Unit.unit;
});
this.executorService.execute(runnablePromise);
return runnablePromise;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy