Skip to content

Commit 306cd58

Browse files
committed
ConflatedBufferedChannel
Signed-off-by: Nikita Koval <[email protected]>
1 parent 184ed7b commit 306cd58

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

kotlinx-coroutines-core/common/src/channels/BufferedChannel.kt

+23-23
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,29 @@ internal open class BufferedChannel<E>(
19921992
return lastSegment
19931993
}
19941994

1995+
/**
1996+
* Completes the channel cancellation procedure.
1997+
*/
1998+
private fun completeCancel(sendersCur: Long) {
1999+
// First, ensure that this channel is closed,
2000+
// obtaining the last segment in the linked list.
2001+
val lastSegment = completeClose(sendersCur)
2002+
// Cancel suspended `send(e)` requests and
2003+
// remove buffered elements in the reverse order.
2004+
removeUnprocessedElements(lastSegment)
2005+
}
2006+
2007+
/**
2008+
* Closes the underlying linked list of segments for further segment addition.
2009+
*/
2010+
private fun closeLinkedList(): ChannelSegment<E> {
2011+
// Choose the last segment.
2012+
val lastSegment = listOf(bufferEndSegment.value, sendSegment.value, receiveSegment.value).maxBy { it.id }
2013+
// Close the linked list of segment for new segment addition
2014+
// and return the last segment in the linked list.
2015+
return lastSegment.close()
2016+
}
2017+
19952018
/**
19962019
* This function marks all empty cells, in the `null` and [IN_BUFFER] state,
19972020
* as closed. Notably, it processes the cells from right to left, and finishes
@@ -2033,29 +2056,6 @@ internal open class BufferedChannel<E>(
20332056
}
20342057
}
20352058

2036-
/**
2037-
* Completes the channel cancellation procedure.
2038-
*/
2039-
private fun completeCancel(sendersCur: Long) {
2040-
// First, ensure that this channel is closed,
2041-
// obtaining the last segment in the linked list.
2042-
val lastSegment = completeClose(sendersCur)
2043-
// Cancel suspended `send(e)` requests and
2044-
// remove buffered elements in the reverse order.
2045-
removeUnprocessedElements(lastSegment)
2046-
}
2047-
2048-
/**
2049-
* Closes the underlying linked list of segments for further segment addition.
2050-
*/
2051-
private fun closeLinkedList(): ChannelSegment<E> {
2052-
// Choose the last segment.
2053-
val lastSegment = listOf(bufferEndSegment.value, sendSegment.value, receiveSegment.value).maxBy { it.id }
2054-
// Close the linked list of segment for new segment addition
2055-
// and return the last segment in the linked list.
2056-
return lastSegment.close()
2057-
}
2058-
20592059
/**
20602060
* Cancels suspended `send(e)` requests and removes buffered elements
20612061
* starting from the last cell in the specified [lastSegment] (it must

0 commit comments

Comments
 (0)