Skip to content

Commit b2f2c1f

Browse files
1zamanelizarov
authored andcommitted
~ Grammar fixes
Also fixes some other minor issues
1 parent 2fb4016 commit b2f2c1f

File tree

12 files changed

+79
-80
lines changed

12 files changed

+79
-80
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import kotlin.coroutines.intrinsics.*
3535
* [send][BroadcastChannel.send] and [close][BroadcastChannel.close] operations that interfere with
3636
* the broadcasting coroutine in hard-to-specify ways.
3737
*
38-
* **Note: This API is obsolete.** It will be deprecated and replaced with
38+
* **Note: This API is obsolete.** It will be deprecated and replaced with the
3939
* [Flow.shareIn][kotlinx.coroutines.flow.shareIn] operator when it becomes stable.
4040
*
4141
* @param start coroutine start option. The default value is [CoroutineStart.LAZY].

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import kotlinx.coroutines.*
1010
* A strategy for buffer overflow handling in [channels][Channel] and [flows][kotlinx.coroutines.flow.Flow] that
1111
* controls what is going to be sacrificed on buffer overflow:
1212
*
13-
* * [SUSPEND] — upstream that is [sending][SendChannel.send] or
13+
* * [SUSPEND] — the upstream that is [sending][SendChannel.send] or
1414
* is [emitting][kotlinx.coroutines.flow.FlowCollector.emit] a value is **suspended** while the buffer is full.
1515
* * [DROP_OLDEST] — drop **the oldest** value in the buffer on overflow, add the new value to the buffer, do not suspend.
16-
* * [DROP_LATEST] — drop **the latest** value that is being added to the buffer right now on buffer overflow,
17-
* so that buffer contents stay the same, do not suspend.
16+
* * [DROP_LATEST] — drop **the latest** value that is being added to the buffer right now on buffer overflow
17+
* (so that buffer contents stay the same), do not suspend.
1818
*/
1919
@ExperimentalCoroutinesApi
2020
public enum class BufferOverflow {
@@ -29,8 +29,8 @@ public enum class BufferOverflow {
2929
DROP_OLDEST,
3030

3131
/**
32-
* Drop **the latest** value that is being added to the buffer right now on buffer overflow,
33-
* so that buffer contents stay the same, do not suspend.
32+
* Drop **the latest** value that is being added to the buffer right now on buffer overflow
33+
* (so that buffer contents stay the same), do not suspend.
3434
*/
3535
DROP_LATEST
3636
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ public interface ChannelIterator<out E> {
511511
* This channel has an array buffer of a fixed `capacity`.
512512
* [Sending][send] suspends only when the buffer is full, and [receiving][receive] suspends only when the buffer is empty.
513513
*
514-
* Buffered channels can be configured with an additional [`onBufferOverflow`][BufferOverflow] parameter. It controls behaviour
514+
* Buffered channels can be configured with an additional [`onBufferOverflow`][BufferOverflow] parameter. It controls the behaviour
515515
* of the channel's [send][Channel.send] function on buffer overflow:
516516
*
517517
* * [SUSPEND][BufferOverflow.SUSPEND] &mdash; the default, suspend `send` on buffer overflow until there is
@@ -576,8 +576,8 @@ public interface Channel<E> : SendChannel<E>, ReceiveChannel<E> {
576576
*
577577
* @param capacity either a positive channel capacity or one of the constants defined in [Channel.Factory].
578578
* @param onBufferOverflow configures an action on buffer overflow (optional, defaults to
579-
* [suspending][BufferOverflow.SUSPEND] attempt to [send][Channel.send] a value,
580-
* supported only when `capacity >= 0` or `capacity = Channel.BUFFERED`,
579+
* a [suspending][BufferOverflow.SUSPEND] attempt to [send][Channel.send] a value,
580+
* supported only when `capacity >= 0` or `capacity == Channel.BUFFERED`,
581581
* implicitly creates a channel with at least one buffered element).
582582
* @throws IllegalArgumentException when [capacity] < -2
583583
*/

kotlinx-coroutines-core/common/src/flow/Builders.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public fun <T> (() -> T).asFlow(): Flow<T> = flow {
7171
}
7272

7373
/**
74-
* Creates a _cold flow that produces a single value from the given functional type.
74+
* Creates a _cold_ flow that produces a single value from the given functional type.
7575
*
7676
* Example of usage:
7777
*

kotlinx-coroutines-core/common/src/flow/Channels.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public fun <T> BroadcastChannel<T>.asFlow(): Flow<T> = flow {
187187
* that is to control backpressure behavior.
188188
*
189189
* **Note: This API is obsolete.** It will be deprecated and replaced with
190-
* [Flow.shareIn] operator when it becomes stable.
190+
* the [Flow.shareIn] operator when it becomes stable.
191191
*/
192192
@FlowPreview
193193
public fun <T> Flow<T>.broadcastIn(

kotlinx-coroutines-core/common/src/flow/Flow.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import kotlin.coroutines.*
4242
* triggers execution of the same code every time it is collected, or if it is a _hot_ stream that emits different
4343
* values from the same running source on each collection. Usually flows represent _cold_ streams, but
4444
* there is a [SharedFlow] subtype that represents _hot_ streams. In addition to that, any flow can be turned
45-
* into a _hot_ one by [stateIn] and [shareIn] operators or by converting the flow into a hot channel
46-
* via [produceIn] operator.
45+
* into a _hot_ one by the [stateIn] and [shareIn] operators, or by converting the flow into a hot channel
46+
* via the [produceIn] operator.
4747
*
4848
* ### Flow builders
4949
*

kotlinx-coroutines-core/common/src/flow/SharedFlow.kt

+38-39
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ import kotlin.native.concurrent.*
1818
* presence of collectors. This is opposed to a regular [Flow], such as defined by the [`flow { ... }`][flow] function,
1919
* which is _cold_ and is started separately for each collector.
2020
*
21-
* **Shared flow never completes**. A call to [Flow.collect] on a shared flow never completes normally and
22-
* so does a coroutine started by [Flow.launchIn] function. An active collector of a shared flow is called a _subscriber_.
21+
* **Shared flow never completes**. A call to [Flow.collect] on a shared flow never completes normally, and
22+
* neither does a coroutine started by the [Flow.launchIn] function. An active collector of a shared flow is called a _subscriber_.
2323
*
2424
* A subscriber of a shared flow can be cancelled, which usually happens when the scope the coroutine is running
2525
* in is cancelled. A subscriber to a shared flow in always [cancellable][Flow.cancellable] and checks for
2626
* cancellation before each emission. Note that most terminal operators like [Flow.toList] would not complete, too,
2727
* when applied to a shared flow, but flow-truncating operators like [Flow.take] and [Flow.takeWhile] can be used on a
2828
* shared flow to turn it into a completing one.
2929
*
30-
* A [mutable shared flow][MutableSharedFlow] is created using [MutableSharedFlow(...)] constructor function.
30+
* A [mutable shared flow][MutableSharedFlow] is created using the [MutableSharedFlow(...)] constructor function.
3131
* Its state can be updated by [emitting][MutableSharedFlow.emit] values to it and performing other operations.
32-
* See [MutableSharedFlow] documentation for details.
32+
* See the [MutableSharedFlow] documentation for details.
3333
*
34-
* [SharedFlow] is useful to broadcast events that happens inside application to subscribers that can come and go.
34+
* [SharedFlow] is useful for broadcasting events that happen inside an application to subscribers that can come and go.
3535
* For example, the following class encapsulates an event bus that distributes events to all subscribers
36-
* in _rendezvous_ manner, suspending until all subscribers process each event:
36+
* in a _rendezvous_ manner, suspending until all subscribers process each event:
3737
*
3838
* ```
3939
* class EventBus {
@@ -46,27 +46,27 @@ import kotlin.native.concurrent.*
4646
* }
4747
* ```
4848
*
49-
* As an alternative to the above usage with `MutableSharedFlow(...)` constructor function,
50-
* any _cold_ [Flow] can be converted to a shared flow using [shareIn] operator.
49+
* As an alternative to the above usage with the `MutableSharedFlow(...)` constructor function,
50+
* any _cold_ [Flow] can be converted to a shared flow using the [shareIn] operator.
5151
*
52-
* There is a specialized implementation of shared flow for a case where the most recent state value needs
52+
* There is a specialized implementation of shared flow for the case where the most recent state value needs
5353
* to be shared. See [StateFlow] for details.
5454
*
5555
* ### Replay cache and buffer
5656
*
57-
* A shared flow keeps a specific number of the most recent values in its _replay cache_. Every new subscribers first
58-
* gets the values from the replay cache and then gets new emitted values. The maximal size of the replay cache is
57+
* A shared flow keeps a specific number of the most recent values in its _replay cache_. Every new subscriber first
58+
* gets the values from the replay cache and then gets new emitted values. The maximum size of the replay cache is
5959
* specified when the shared flow is created by the `replay` parameter. A snapshot of the current replay cache
60-
* is available via [replayCache] property and it can be reset with [MutableSharedFlow.resetReplayCache] function.
60+
* is available via the [replayCache] property and it can be reset with the [MutableSharedFlow.resetReplayCache] function.
6161
*
62-
* A replay cache provides buffer for emissions to the shared flow. Buffer space allows slow subscribers to
62+
* A replay cache also provides buffer for emissions to the shared flow, allowing slow subscribers to
6363
* get values from the buffer without suspending emitters. The buffer space determines how much slow subscribers
64-
* can lag from the fast ones. When creating a shared flow additional buffer capacity beyond replay can be reserved
65-
* using `extraBufferCapacity` parameter.
64+
* can lag from the fast ones. When creating a shared flow, additional buffer capacity beyond replay can be reserved
65+
* using the `extraBufferCapacity` parameter.
6666
*
6767
* A shared flow with a buffer can be configured to avoid suspension of emitters on buffer overflow using
68-
* `onBufferOverflow` parameter, which is equal to one of the entries of [BufferOverflow] enum. When a strategy other
69-
* than [SUSPENDED][BufferOverflow.SUSPEND] is configured emissions to the shared flow never suspend.
68+
* the `onBufferOverflow` parameter, which is equal to one of the entries of the [BufferOverflow] enum. When a strategy other
69+
* than [SUSPENDED][BufferOverflow.SUSPEND] is configured, emissions to the shared flow never suspend.
7070
*
7171
* ### SharedFlow vs BroadcastChannel
7272
*
@@ -79,9 +79,9 @@ import kotlin.native.concurrent.*
7979
* * `SharedFlow` supports configurable replay and buffer overflow strategy.
8080
* * `SharedFlow` has a clear separation into a read-only `SharedFlow` interface and a [MutableSharedFlow].
8181
* * `SharedFlow` cannot be closed like `BroadcastChannel` and can never represent a failure.
82-
* All errors and completion signals shall be explicitly _materialized_ if needed.
82+
* All errors and completion signals should be explicitly _materialized_ if needed.
8383
*
84-
* To migrate [BroadcastChannel] usage to [SharedFlow] start by replacing `BroadcastChannel(capacity)`
84+
* To migrate [BroadcastChannel] usage to [SharedFlow], start by replacing usages of the `BroadcastChannel(capacity)`
8585
* constructor with `MutableSharedFlow(0, extraBufferCapacity=capacity)` (broadcast channel does not replay
8686
* values to new subscribers). Replace [send][BroadcastChannel.send] and [offer][BroadcastChannel.offer] calls
8787
* with [emit][MutableStateFlow.emit] and [tryEmit][MutableStateFlow.tryEmit], and convert subscribers' code to flow operators.
@@ -106,7 +106,7 @@ import kotlin.native.concurrent.*
106106
*
107107
* **`SharedFlow` interface is not stable for inheritance in 3rd party libraries**, as new methods
108108
* might be added to this interface in the future, but is stable for use.
109-
* Use `MutableSharedFlow(replay, ...)` constructor function to create an implementation.
109+
* Use the `MutableSharedFlow(replay, ...)` constructor function to create an implementation.
110110
*/
111111
@ExperimentalCoroutinesApi
112112
public interface SharedFlow<out T> : Flow<T> {
@@ -121,9 +121,9 @@ public interface SharedFlow<out T> : Flow<T> {
121121
* Its instance with the given configuration parameters can be created using `MutableSharedFlow(...)`
122122
* constructor function.
123123
*
124-
* See [SharedFlow] documentation for details on shared flows.
124+
* See the [SharedFlow] documentation for details on shared flows.
125125
*
126-
* `MutableSharedFlow` is a [SharedFlow] that also provides abilities to [emit] a value,
126+
* `MutableSharedFlow` is a [SharedFlow] that also provides the abilities to [emit] a value,
127127
* to [tryEmit] without suspension if possible, to track the [subscriptionCount],
128128
* and to [resetReplayCache].
129129
*
@@ -142,17 +142,17 @@ public interface SharedFlow<out T> : Flow<T> {
142142
public interface MutableSharedFlow<T> : SharedFlow<T>, FlowCollector<T> {
143143
/**
144144
* Tries to emit a [value] to this shared flow without suspending. It returns `true` if the value was
145-
* emitted successfully. When this function returns `false` it means that the call to a plain [emit]
145+
* emitted successfully. When this function returns `false`, it means that the call to a plain [emit]
146146
* function will suspend until there is a buffer space available.
147147
*
148-
* A shared flow configured with [BufferOverflow] strategy other than [SUSPEND][BufferOverflow.SUSPEND]
148+
* A shared flow configured with a [BufferOverflow] strategy other than [SUSPEND][BufferOverflow.SUSPEND]
149149
* (either [DROP_OLDEST][BufferOverflow.DROP_OLDEST] or [DROP_LATEST][BufferOverflow.DROP_LATEST]) never
150-
* suspends on [emit] and thus `tryEmit` to such a shared flow always returns `true`.
150+
* suspends on [emit], and thus `tryEmit` to such a shared flow always returns `true`.
151151
*/
152152
public fun tryEmit(value: T): Boolean
153153

154154
/**
155-
* A number of subscribers (active collectors) to this shared flow.
155+
* The number of subscribers (active collectors) to this shared flow.
156156
*
157157
* This state can be used to react to changes in the number of subscriptions to this shared flow.
158158
* For example, if you need to call `onActive` function when the first subscriber appears and `onInactive`
@@ -171,29 +171,28 @@ public interface MutableSharedFlow<T> : SharedFlow<T>, FlowCollector<T> {
171171
public val subscriptionCount: StateFlow<Int>
172172

173173
/**
174-
* Resets [replayCache] of this shared flow to an empty state.
175-
* New subscribers will be receiving only the values emitted after this call,
174+
* Resets the [replayCache] of this shared flow to an empty state.
175+
* New subscribers will be receiving only the values that were emitted after this call,
176176
* while old subscribers will still be receiving previously buffered values.
177-
* To reset a shared flow to an initial value, emit this value after this call.
177+
* To reset a shared flow to an initial value, emit the value after this call.
178178
*
179179
* On a [MutableStateFlow], which always contains a single value, this function is not
180-
* supported and throws [UnsupportedOperationException]. To reset a [MutableStateFlow]
181-
* to an initial value just update its [value][MutableStateFlow.value].
180+
* supported, and throws an [UnsupportedOperationException]. To reset a [MutableStateFlow]
181+
* to an initial value, just update its [value][MutableStateFlow.value].
182182
*/
183-
@Suppress("UNCHECKED_CAST")
184183
public fun resetReplayCache()
185184
}
186185

187186
/**
188187
* Creates a [MutableSharedFlow] with the given configuration parameters.
189188
*
190-
* This function throws [IllegalArgumentException] on unsupported values of parameters of combinations thereof.
189+
* This function throws [IllegalArgumentException] on unsupported values of parameters or combinations thereof.
191190
*
192191
* @param replay the number of values replayed to new subscribers (cannot be negative).
193192
* @param extraBufferCapacity the number of values buffered in addition to `replay`.
194193
* [emit][MutableSharedFlow.emit] does not suspend while there is a buffer space remaining (optional, cannot be negative, defaults to zero).
195194
* @param onBufferOverflow configures an action on buffer overflow (optional, defaults to
196-
* [suspending][BufferOverflow.SUSPEND] attempt to [emit][MutableSharedFlow.emit] a value,
195+
* [suspending][BufferOverflow.SUSPEND] attempts to [emit][MutableSharedFlow.emit] a value,
197196
* supported only when `replay > 0` or `extraBufferCapacity > 0`).
198197
*/
199198
@Suppress("FunctionName", "UNCHECKED_CAST")
@@ -341,7 +340,7 @@ private class SharedFlowImpl<T>(
341340
// Fast path without collectors -> no buffering
342341
if (nCollectors == 0) return tryEmitNoCollectorsLocked(value) // always returns true
343342
// With collectors we'll have to buffer
344-
// cannot emit now if buffer is full && blocked by slow collectors
343+
// cannot emit now if buffer is full & blocked by slow collectors
345344
if (bufferSize >= bufferCapacity && minCollectorIndex <= replayIndex) {
346345
when (onBufferOverflow) {
347346
BufferOverflow.SUSPEND -> return false // will suspend
@@ -448,7 +447,7 @@ private class SharedFlowImpl<T>(
448447
return index
449448
}
450449

451-
// Is called when collector disappears of changes index, returns a list of continuations to resume after lock
450+
// Is called when a collector disappears or changes index, returns a list of continuations to resume after lock
452451
internal fun updateCollectorIndexLocked(oldIndex: Long): List<Continuation<Unit>>? {
453452
assert { oldIndex >= minCollectorIndex }
454453
if (oldIndex > minCollectorIndex) return null // nothing changes, it was not min
@@ -520,7 +519,7 @@ private class SharedFlowImpl<T>(
520519
assert { newHead >= head }
521520
// cleanup items we don't have to buffer anymore (because head is about to move)
522521
for (index in head until newHead) buffer!!.setBufferAt(index, null)
523-
// update all state variable to newly computed values
522+
// update all state variables to newly computed values
524523
replayIndex = newReplayIndex
525524
minCollectorIndex = newMinCollectorIndex
526525
bufferSize = (newBufferEndIndex - newHead).toInt()
@@ -531,7 +530,7 @@ private class SharedFlowImpl<T>(
531530
assert { replayIndex <= this.head + bufferSize }
532531
}
533532

534-
// :todo:
533+
// Removes all the NO_VALUE items from the end of the queue and reduces its size
535534
private fun cleanupTailLocked() {
536535
// If we have synchronous case, then keep one emitter queued
537536
if (bufferCapacity == 0 && queueSize <= 1) return // return, don't clear it
@@ -563,7 +562,7 @@ private class SharedFlowImpl<T>(
563562

564563
// returns -1 if cannot peek value without suspension
565564
private fun tryPeekLocked(slot: SharedFlowSlot): Long {
566-
// return buffered value is possible
565+
// return buffered value if possible
567566
val index = slot.index
568567
if (index < bufferEndIndex) return index
569568
if (bufferCapacity > 0) return -1L // if there's a buffer, never try to rendezvous with emitters

0 commit comments

Comments
 (0)