@@ -40,18 +40,34 @@ public fun <T1, T2> Sink<T1>.contraMap(transform: (T2) -> T1): Sink<T2> = Sink {
40
40
41
41
/* *
42
42
* Collects from a [Flow] by converting each item into a [WorkflowAction] and then sending them
43
- * to the [actionSink]. This operator propagates back pressure from the workflow runtime, so if there
44
- * is a lot of contention on the workflow runtime the flow will be suspended while the action is
45
- * queued.
43
+ * to the [actionSink]. This may be used as an alternative to a [asWorker] for certain [Flow]s.
44
+ *
45
+ * Unlike merely calling [collect][Flow.collect] yourself and emitting an action directly to the
46
+ * sink, this operator propagates back pressure from the workflow runtime, so if there is a lot of
47
+ * contention on the workflow runtime the flow will be suspended while the action is queued and only
48
+ * resumed _after_ the action has been applied.
46
49
*
47
50
* Example:
48
- * ```
49
- * context.runningSideEffect("collector") {
50
- * myFlow.collectToSink(context.actionSink) { value ->
51
- * action("collect") { setOutput(value) }
51
+ * ```kotlin
52
+ * class MyWorkflow(
53
+ * private val myFlow: Flow<…>
54
+ * ) {
55
+ *
56
+ * // Omitting types for brevity.
57
+ * override fun render() {
58
+ * context.runningSideEffect("collector") {
59
+ * myFlow.collectToSink(context.actionSink) { value ->
60
+ * action("collect") { setOutput(value) }
61
+ * }
62
+ * }
52
63
* }
53
64
* }
54
65
* ```
66
+ *
67
+ * > **Warning:** Be careful using this from `runningSideEffect` when the source [Flow] comes from
68
+ * > state or props. The side effect will capture those values when it first runs, and if the instance
69
+ * > of the flow changes in a future render pass, the side effect will still be collecting the stale
70
+ * > [Flow]. In this case
55
71
*/
56
72
public suspend fun <T , PropsT , StateT , OutputT > Flow<T>.collectToSink (
57
73
actionSink : Sink <WorkflowAction <PropsT , StateT , OutputT >>,
0 commit comments