Skip to content

Commit 71e8e45

Browse files
Upgrade coroutines dep to 1.3.0-M1.
- Some things that were `@FlowPreview` have been graduated to `@ExperimentalCoroutinesApi`. - Breakage in `CoroutineWorkflow` was caused by Kotlin/kotlinx.coroutines#1158. - Breakage in `ReactorAsWorkflowIntegrationTest` was probably caused by Kotlin/kotlinx.coroutines#1239.
1 parent 01ad7f7 commit 71e8e45

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

kotlin/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ buildscript {
3535
'intellijAnnotations': '13.0',
3636
'junit': '4.12',
3737
'kotlin': '1.3.21',
38-
'kotlinCoroutines': '1.2.1',
38+
'kotlinCoroutines': '1.3.0-M1',
3939
'ktlintPlugin': '5.1.0',
4040
'mavenPublishPlugin': '0.8.0',
4141
'mockito': '2.7.5',

kotlin/legacy/legacy-workflow-core/src/main/java/com/squareup/workflow/legacy/CoroutineWorkflow.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.squareup.workflow.legacy
1919

20+
import kotlinx.coroutines.CancellationException
2021
import kotlinx.coroutines.CoroutineScope
2122
import kotlinx.coroutines.Deferred
2223
import kotlinx.coroutines.async
@@ -74,10 +75,12 @@ fun <S : Any, E : Any, O : Any> CoroutineScope.workflow(
7475
// if the event channel was closed.
7576
try {
7677
events.offer(event)
78+
} catch (e: CancellationException) {
79+
// This means that the workflow was cancelled. Senders shouldn't care if the workflow
80+
// accepted the event or not.
7781
} catch (e: ClosedSendChannelException) {
78-
// This may mean the workflow was canceled or finished, or that the workflow closed the
79-
// events channel itself. Either way, senders shouldn't care if the workflow accepted the
80-
// event or not.
82+
// This may mean the workflow finished or that the workflow closed the events channel
83+
// itself. Senders shouldn't care if the workflow accepted the event or not.
8184
}
8285
}
8386

kotlin/legacy/legacy-workflow-core/src/test/java/com/squareup/workflow/legacy/CoroutineWorkflowTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import kotlinx.coroutines.CancellationException
2121
import kotlinx.coroutines.CoroutineName
2222
import kotlinx.coroutines.CoroutineScope
2323
import kotlinx.coroutines.Dispatchers.Unconfined
24-
import kotlinx.coroutines.cancel
2524
import kotlinx.coroutines.channels.ReceiveChannel
2625
import kotlinx.coroutines.channels.consume
2726
import kotlinx.coroutines.suspendCancellableCoroutine

kotlin/legacy/legacy-workflow-core/src/test/java/com/squareup/workflow/legacy/ReactorAsWorkflowIntegrationTest.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class ReactorAsWorkflowIntegrationTest {
103103
subscribeToState(workflow)
104104
workflow.cancel()
105105

106+
assertEquals(SecondState("hello"), stateSub.poll())
106107
assertFailsWith<CancellationException> { stateSub.poll() }
107108
assertTrue(stateSub.isClosedForReceive)
108109
}
@@ -166,6 +167,7 @@ class ReactorAsWorkflowIntegrationTest {
166167
assertFalse(resultSub.isCompleted)
167168

168169
secondStateDeferred.complete(SecondState("foo"))
170+
assertEquals(SecondState("foo"), stateSub.poll())
169171
assertTrue(stateSub.isClosedForReceive)
170172
assertEquals("all done", resultSub.getCompleted())
171173
}
@@ -255,7 +257,8 @@ class ReactorAsWorkflowIntegrationTest {
255257
assertTrue(cancelled)
256258
}
257259

258-
@Test fun `exception is propagated when state subscriber throws from second onNext asynchronously`() {
260+
@Test
261+
fun `exception is propagated when state subscriber throws from second onNext asynchronously`() {
259262
val trigger = CompletableDeferred<Unit>()
260263
reactor = object : MockReactor() {
261264
override suspend fun onReact(
@@ -372,6 +375,7 @@ class ReactorAsWorkflowIntegrationTest {
372375
assertFalse(resultSub.isCompleted)
373376

374377
workflow.sendEvent("foo")
378+
assertEquals(SecondState("foo"), stateSub.poll())
375379
assertTrue(stateSub.isClosedForReceive)
376380
assertEquals("i heard you like events", resultSub.getCompleted())
377381
}
@@ -404,6 +408,7 @@ class ReactorAsWorkflowIntegrationTest {
404408
}
405409
}
406410
start("foo")
411+
assertEquals(FirstState("foo"), stateSub.poll())
407412
trigger.complete(Unit)
408413

409414
runBlocking {

kotlin/workflow-core/src/main/java/com/squareup/workflow/Worker.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import com.squareup.workflow.Worker.Emitter
2323
import kotlinx.coroutines.CoroutineScope
2424
import kotlinx.coroutines.Deferred
2525
import kotlinx.coroutines.ExperimentalCoroutinesApi
26-
import kotlinx.coroutines.FlowPreview
2726
import kotlinx.coroutines.channels.BroadcastChannel
2827
import kotlinx.coroutines.channels.ReceiveChannel
2928
import kotlinx.coroutines.channels.consumeEach
@@ -329,7 +328,7 @@ inline fun <reified T> ReceiveChannel<T>.asWorker(
329328
* This **SHOULD NOT** be used in production code.
330329
*/
331330
@VeryExperimentalWorkflow
332-
@FlowPreview
331+
@ExperimentalCoroutinesApi
333332
inline fun <reified T> Flow<T>.asWorker(
334333
key: String = ""
335334
): Worker<T> = create(key) { emitAll(this@asWorker) }
@@ -370,7 +369,7 @@ suspend inline fun <T> Emitter<T>.emitAll(
370369
* This **SHOULD NOT** be used in production code.
371370
*/
372371
@VeryExperimentalWorkflow
373-
@FlowPreview
372+
@ExperimentalCoroutinesApi
374373
suspend inline fun <T> Emitter<T>.emitAll(flow: Flow<T>) {
375374
flow.collect { emitOutput(it) }
376375
}

kotlin/workflow-runtime/src/main/java/com/squareup/workflow/WorkflowHost.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import kotlinx.coroutines.CoroutineName
2323
import kotlinx.coroutines.CoroutineScope
2424
import kotlinx.coroutines.ExperimentalCoroutinesApi
2525
import kotlinx.coroutines.GlobalScope
26-
import kotlinx.coroutines.InternalCoroutinesApi
27-
import kotlinx.coroutines.ObsoleteCoroutinesApi
2826
import kotlinx.coroutines.channels.Channel
2927
import kotlinx.coroutines.channels.ReceiveChannel
3028
import kotlinx.coroutines.channels.consume
@@ -160,7 +158,7 @@ interface WorkflowHost<out OutputT : Any, out RenderingT> {
160158
* use [WorkflowHost.Factory] to create a [WorkflowHost], or one of the stream operators for your
161159
* favorite Rx library to map a stream of [InputT]s into [Update]s.
162160
*/
163-
@UseExperimental(InternalCoroutinesApi::class, ObsoleteCoroutinesApi::class)
161+
@UseExperimental(ExperimentalCoroutinesApi::class)
164162
suspend fun <InputT, StateT, OutputT : Any, RenderingT> runWorkflowTree(
165163
workflow: StatefulWorkflow<InputT, StateT, OutputT, RenderingT>,
166164
inputs: () -> ReceiveChannel<InputT>,

0 commit comments

Comments
 (0)