@@ -30,8 +30,19 @@ public abstract class AbstractChannel<E> : Channel<E> {
30
30
31
31
// ------ extension points for buffered channels ------
32
32
33
+ /* *
34
+ * Returns `true` if this channel has buffer.
35
+ */
33
36
protected abstract val hasBuffer: Boolean
37
+
38
+ /* *
39
+ * Returns `true` if this channel's buffer is empty.
40
+ */
34
41
protected abstract val isBufferEmpty: Boolean
42
+
43
+ /* *
44
+ * Returns `true` if this channel's buffer is full.
45
+ */
35
46
protected abstract val isBufferFull: Boolean
36
47
37
48
/* *
@@ -49,7 +60,14 @@ public abstract class AbstractChannel<E> : Channel<E> {
49
60
50
61
// ------ state functions for concrete implementations ------
51
62
63
+ /* *
64
+ * Returns non-null closed token if it is first in the queue.
65
+ */
52
66
protected val closedForReceive: Any? get() = queue.next() as ? Closed <* >
67
+
68
+ /* *
69
+ * Returns non-null closed token if it is last in the queue.
70
+ */
53
71
protected val closedForSend: Any? get() = queue.prev() as ? Closed <* >
54
72
55
73
// ------ SendChannel ------
@@ -117,6 +135,9 @@ public abstract class AbstractChannel<E> : Channel<E> {
117
135
}
118
136
}
119
137
138
+ /* *
139
+ * Retrieves first receiving waiter from the queue or returns closed token.
140
+ */
120
141
protected fun takeFirstReceiveOrPeekClosed (): ReceiveOrClosed <E >? =
121
142
queue.removeFirstIfIsInstanceOfOrPeekIf<ReceiveOrClosed <E >> { it is Closed <* > }
122
143
@@ -219,6 +240,9 @@ public abstract class AbstractChannel<E> : Channel<E> {
219
240
220
241
override fun iterator (): ChannelIterator <E > = Iterator (this )
221
242
243
+ /* *
244
+ * Retrieves first sending waiter from the queue or returns closed token.
245
+ */
222
246
protected fun takeFirstSendOrPeekClosed (): Send ? =
223
247
queue.removeFirstIfIsInstanceOfOrPeekIf<Send > { it is Closed <* > }
224
248
@@ -297,12 +321,18 @@ public abstract class AbstractChannel<E> : Channel<E> {
297
321
}
298
322
}
299
323
324
+ /* *
325
+ * Represents sending waiter in the queue.
326
+ */
300
327
protected interface Send {
301
328
val pollResult: Any? // E | Closed
302
329
fun tryResumeSend (): Any?
303
330
fun completeResumeSend (token : Any )
304
331
}
305
332
333
+ /* *
334
+ * Represents receiver waiter in the queue or closed token.
335
+ */
306
336
protected interface ReceiveOrClosed <in E > {
307
337
val offerResult: Any // OFFER_SUCCESS | Closed
308
338
fun tryResumeReceive (value : E ): Any?
0 commit comments