Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Jun 18, 2024
1 parent cea8103 commit 498caf5
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,21 @@ protected StarlarkBaseExternalContext(
.factory());
}

/**
* Mark the evaluation using this context as otherwise successful. This is used to determine how
* to clean up resources in {@link #close()}.
*/
public final void markSuccessful() {
wasSuccessful = true;
}

@Override
public final void close() throws EvalException, IOException {
// Cancel all pending async tasks.
boolean hadPendingItems = ensureNoPendingAsyncTasks();
// Wait for all (cancelled) async tasks to complete before cleaning up the working directory.
// This is necessary because downloads may still be in progress and could end up writing to the
// working directory during deletion, which would cause an error.
executorService.close();
if (shouldDeleteWorkingDirectory(wasSuccessful)) {
workingDirectory.deleteTree();
Expand All @@ -203,7 +211,7 @@ public final void close() throws EvalException, IOException {
}
}

public final boolean ensureNoPendingAsyncTasks() {
private boolean ensureNoPendingAsyncTasks() {
boolean hadPendingItems = false;
for (AsyncTask task : asyncTasks) {
if (!task.cancel()) {
Expand All @@ -225,7 +233,7 @@ public final boolean ensureNoPendingAsyncTasks() {

// There is no unregister(). We don't have that many futures in each repository and it just
// introduces the failure mode of erroneously unregistering async work that's not done.
protected void registerAsyncTask(AsyncTask task) {
protected final void registerAsyncTask(AsyncTask task) {
asyncTasks.add(task);
}

Expand Down

0 comments on commit 498caf5

Please sign in to comment.