Skip to content

Commit 90c574a

Browse files
committed
remove homemade stateIn operator in favor of the stable kotlinx one
fixes #222
1 parent 81bdcb1 commit 90c574a

File tree

1 file changed

+1
-25
lines changed

1 file changed

+1
-25
lines changed

workflow-tracing/src/test/java/com/squareup/workflow1/diagnostic/tracing/TracingWorkflowInterceptorTest.kt

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,25 @@ import com.squareup.workflow1.action
88
import com.squareup.workflow1.asWorker
99
import com.squareup.workflow1.renderWorkflowIn
1010
import com.squareup.workflow1.runningWorker
11-
import kotlinx.coroutines.CompletableDeferred
1211
import kotlinx.coroutines.CoroutineScope
1312
import kotlinx.coroutines.Dispatchers.Unconfined
1413
import kotlinx.coroutines.ExperimentalCoroutinesApi
15-
import kotlinx.coroutines.Job
1614
import kotlinx.coroutines.cancel
1715
import kotlinx.coroutines.channels.Channel
1816
import kotlinx.coroutines.channels.Channel.Factory.UNLIMITED
19-
import kotlinx.coroutines.flow.Flow
20-
import kotlinx.coroutines.flow.MutableStateFlow
21-
import kotlinx.coroutines.flow.StateFlow
2217
import kotlinx.coroutines.flow.asFlow
2318
import kotlinx.coroutines.flow.collect
2419
import kotlinx.coroutines.flow.map
2520
import kotlinx.coroutines.flow.onEach
2621
import kotlinx.coroutines.flow.receiveAsFlow
22+
import kotlinx.coroutines.flow.stateIn
2723
import kotlinx.coroutines.flow.takeWhile
28-
import kotlinx.coroutines.launch
2924
import kotlinx.coroutines.runBlocking
3025
import kotlinx.coroutines.yield
3126
import okio.Buffer
3227
import okio.buffer
3328
import okio.source
3429
import org.mockito.kotlin.mock
35-
import kotlin.coroutines.coroutineContext
3630
import kotlin.test.Test
3731
import kotlin.test.assertEquals
3832

@@ -92,24 +86,6 @@ internal class TracingWorkflowInterceptorTest {
9286
assertEquals(expected.readUtf8(), buffer.readUtf8())
9387
}
9488

95-
/**
96-
* TODO(https://github.com/square/workflow/issues/1191) Remove once stateIn ships.
97-
*/
98-
@OptIn(ExperimentalCoroutinesApi::class)
99-
private suspend fun <T> Flow<T>.stateIn(scope: CoroutineScope): StateFlow<T> {
100-
val stateFlow = CompletableDeferred<MutableStateFlow<T>>(parent = coroutineContext[Job])
101-
scope.launch {
102-
collect {
103-
if (stateFlow.isCompleted) {
104-
stateFlow.getCompleted().value = it
105-
} else {
106-
stateFlow.complete(MutableStateFlow(it))
107-
}
108-
}
109-
}
110-
return stateFlow.await()
111-
}
112-
11389
private inner class TestWorkflow : StatefulWorkflow<Int, String, String, String>() {
11490

11591
private val channel = Channel<String>(UNLIMITED)

0 commit comments

Comments
 (0)