Skip to content

Commit

Permalink
Merge pull request #79 from spotify/roger/Void_task
Browse files Browse the repository at this point in the history
Add support for CompletionStage<Void> tasks in the ConcurrencyReducer
  • Loading branch information
rschildmeijer authored Nov 5, 2020
2 parents 0cccde6 + e075e40 commit 0f6c39a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/spotify/futures/ConcurrencyReducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ private void invoke(final CompletableFuture<T> response,

future.whenComplete(
(result, t) -> {
if (result != null) {
if (t != null) {
limit.release();
response.complete(result);
response.completeExceptionally(t);
pump();
} else {
limit.release();
response.completeExceptionally(t);
response.complete(result);
pump();
}
});
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/com/spotify/futures/ConcurrencyReducerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public void testNullJob() throws Exception {
limiter.add(null);
}

@Test()
public void testVoidJob() {
final ConcurrencyReducer<Void> limiter = ConcurrencyReducer.create(1, 10);
final CompletionStage<Void> task = CompletableFuture.completedFuture(null);
assertTrue(task.toCompletableFuture().isDone());

final CompletableFuture<Void> stage = limiter.add(() -> task);
assertTrue(stage.isDone());
}

@Test
public void testJobReturnsNull() throws Exception {
final ConcurrencyReducer<String> limiter = ConcurrencyReducer.create(1, 10);
Expand Down

0 comments on commit 0f6c39a

Please sign in to comment.