Skip to content

Commit

Permalink
+ made SequentialExecutor a functional interface using default method
Browse files Browse the repository at this point in the history
  • Loading branch information
q3769 committed May 16, 2024
1 parent 8016870 commit 28db313
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.q3769</groupId>
<artifactId>conseq4j</artifactId>
<version>20230922.20230924.20240515</version>
<version>20230922.20230924.20240516</version>
<packaging>jar</packaging>
<name>conseq4j</name>
<description>A Java concurrent API to sequence related tasks while concurring unrelated ones</description>
Expand Down
19 changes: 1 addition & 18 deletions src/main/java/conseq4j/execute/ConseqExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@
import conseq4j.Terminable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.*;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
import lombok.NonNull;
Expand Down Expand Up @@ -93,17 +87,6 @@ private static ConditionFactory await() {
return Awaitility.await().forever();
}

/**
* @param command the command to run asynchronously in proper sequence
* @param sequenceKey the key under which this task should be sequenced
* @return future result of the command, not downcast-able from the basic {@link Future} interface.
* @see ConseqExecutor#submit(Callable, Object)
*/
@Override
public @NonNull Future<Void> execute(@NonNull Runnable command, @NonNull Object sequenceKey) {
return submit(Executors.callable(command, null), sequenceKey);
}

/**
* Tasks of different sequence keys execute in parallel, pending thread availability from the backing
* {@link #workerExecutorService}.
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/conseq4j/execute/SequentialExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package conseq4j.execute;

import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
Expand All @@ -48,8 +49,9 @@ public interface SequentialExecutor {
* @param sequenceKey the key under which all tasks are executed sequentially
* @return future holding run status of the submitted command
*/
Future<Void> execute(Runnable command, Object sequenceKey);

default Future<Void> execute(Runnable command, Object sequenceKey) {
return submit(Executors.callable(command, null), sequenceKey);
}
/**
* @param task the Callable task to run sequentially with others under the same sequence key
* @param sequenceKey the key under which all tasks are executed sequentially
Expand Down

0 comments on commit 28db313

Please sign in to comment.