Skip to content

Commit 71cda3e

Browse files
authored
2.x: document (internal) SimpleQueue (#5056)
1 parent 00f53ae commit 71cda3e

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/main/java/io/reactivex/internal/fuseable/SimplePlainQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.reactivex.annotations.Nullable;
1717

1818
/**
19-
* Override of the SimpleQueue interface with no throws Exception on poll.
19+
* Override of the SimpleQueue interface with no throws Exception on poll().
2020
*
2121
* @param <T> the value type to enqueue and dequeue, not null
2222
*/

src/main/java/io/reactivex/internal/fuseable/SimpleQueue.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
package io.reactivex.internal.fuseable;
1515

16-
import io.reactivex.annotations.Nullable;
16+
import io.reactivex.annotations.*;
1717

1818
/**
1919
* A minimalist queue interface without the method bloat of java.util.Collection and java.util.Queue.
@@ -22,17 +22,50 @@
2222
*/
2323
public interface SimpleQueue<T> {
2424

25-
boolean offer(T value);
25+
/**
26+
* Atomically enqueue a single.
27+
* @param value the value to enqueue, not null
28+
* @return true if successful, false if the value was not enqueued
29+
* likely due to reaching the queue capacity)
30+
*/
31+
boolean offer(@NonNull T value);
2632

27-
boolean offer(T v1, T v2);
33+
/**
34+
* Atomically enqueue two values.
35+
* @param v1 the first value to enqueue, not null
36+
* @param v2 the second value to enqueue, not null
37+
* @return true if successful, false if the value was not enqueued
38+
* likely due to reaching the queue capacity)
39+
*/
40+
boolean offer(@NonNull T v1, @NonNull T v2);
2841

2942
/**
30-
* @return null to indicate an empty queue
43+
* Tries to dequeue a value (non-null) or returns null if
44+
* the queue is empty.
45+
* <p>
46+
* If the producer uses {@link #offer(Object, Object)} and
47+
* when polling in pairs, if the first poll() returns a non-null
48+
* item, the second poll() is guaranteed to return a non-null item
49+
* as well.
50+
* @return the item or null to indicate an empty queue
51+
* @throws Exception if some pre-processing of the dequeued
52+
* item (usually through fused functions) throws.
3153
*/
3254
@Nullable
3355
T poll() throws Exception;
3456

57+
/**
58+
* Returns true if the queue is empty.
59+
* <p>
60+
* Note however that due to potential fused functions in {@link #poll()}
61+
* it is possible this method returns false but then poll() returns null
62+
* because the fused function swallowed the available item(s).
63+
* @return true if the queue is empty
64+
*/
3565
boolean isEmpty();
3666

67+
/**
68+
* Removes all enqueued items from this queue.
69+
*/
3770
void clear();
3871
}

0 commit comments

Comments
 (0)