Create a NestedSet method isReady to determine whether the NestedSet requires blocking.
This tells us whether the contents require blocking without exposing the raw children.
PiperOrigin-RevId: 300780177
diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java
index 8f82698..04560d7 100644
--- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java
+++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/NestedSet.java
@@ -298,6 +298,16 @@
return children instanceof ListenableFuture;
}
+ /**
+ * Returns true if the contents of this set are currently available in memory.
+ *
+ * <p>Only returns false if this set {@link #isFromStorage} and the contents are not fully
+ * deserialized.
+ */
+ public boolean isReady() {
+ return !isFromStorage() || ((ListenableFuture<Object[]>) children).isDone();
+ }
+
/** Returns the single element; only call this if {@link #isSingleton} returns true. */
public E getSingleton() {
Preconditions.checkState(isSingleton());
diff --git a/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java b/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java
index 0752f9e..3d40e9c 100644
--- a/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java
+++ b/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java
@@ -324,4 +324,19 @@
NestedSet<?> inMemoryNestedSet = NestedSetBuilder.create(Order.STABLE_ORDER, "a", "b");
assertThat(inMemoryNestedSet.isFromStorage()).isFalse();
}
+
+ @Test
+ public void isReady_inMemory() {
+ NestedSet<?> inMemoryNestedSet = NestedSetBuilder.create(Order.STABLE_ORDER, "a", "b");
+ assertThat(inMemoryNestedSet.isReady()).isTrue();
+ }
+
+ @Test
+ public void isReady_fromStorage() {
+ SettableFuture<Object[]> future = SettableFuture.create();
+ NestedSet<?> deserializingNestedSet = NestedSet.withFuture(Order.STABLE_ORDER, future);
+ assertThat(deserializingNestedSet.isReady()).isFalse();
+ future.set(new Object[] {"a", "b"});
+ assertThat(deserializingNestedSet.isReady()).isTrue();
+ }
}