Skip to content

Commit

Permalink
fix: wait until adding instance to sink is complete
Browse files Browse the repository at this point in the history
...to avoid the sink being closed while asynchronous operations are
still pending.

ING-4479
  • Loading branch information
stempler committed Nov 11, 2024
1 parent f2768d8 commit 52044f5
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -227,7 +228,7 @@ public void dispose() {

@Override
protected void internalAddInstance(final Instance instance) {
dbThread.execute(new Runnable() {
var future = dbThread.submit(new Runnable() {

@Override
public void run() {
Expand All @@ -240,6 +241,16 @@ public void run() {
}
}
});

// wait for adding instance to database to complete, otherwise the
// transformation might complete before the instance is actually added
try {
future.get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}

@Override
Expand Down

0 comments on commit 52044f5

Please sign in to comment.