Skip to content

Commit 8e2ac2b

Browse files
committed
Update readme
1 parent f99a601 commit 8e2ac2b

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ GlobalScope.launch {
3131
* [core](core/README.md) — Kotlin/JVM implementation of common coroutines with additional features:
3232
* `Dispatchers.IO` dispatcher for blocking coroutines;
3333
* `Executor.asCoroutineDispatcher()` extension, custom thread pools, and more.
34+
* [core-test](core/README.md) — test utilities for coroutines, currently with one feature:
35+
* `MainDispatcherInjector.inject()` to override `Dispatchers.Main` in tests.
3436
* [js](js/README.md) — Kotlin/JS implementation of common coroutines with `Promise` support.
3537
* [native](native/README.md) — Kotlin/Native implementation of common coroutines with `runBlocking` single-threaded event loop.
3638
* [reactive](reactive/README.md) — modules that provide builders and iteration support for various reactive streams libraries:

RELEASE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ To release new `<version>` of `kotlinx-coroutines`:
1212
`git merge origin/master`
1313

1414
4. Search & replace `<old-version>` with `<version>` across the project files. Should replace in:
15-
* [`README.md`](README.md)
15+
* [`README.md`](README.md) (native, core, core-test modules)
1616
* [`coroutines-guide.md`](docs/coroutines-guide.md)
1717
* [`gradle.properties`](gradle.properties)
1818
* [`ui/kotlinx-coroutines-android/example-app/gradle.properties`](ui/kotlinx-coroutines-android/example-app/gradle.properties)

core/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ Module name below corresponds to the artifact name in Maven/Gradle.
55

66
## Modules
77

8-
* [kotlinx-coroutines-core](kotlinx-coroutines-core/README.md) -- core coroutine builders and synchronization primitives.
8+
* [kotlinx-coroutines-core](kotlinx-coroutines-core/README.md) &mdash; core coroutine builders and synchronization primitives.
9+
* [kotlinx-coroutines-core-test](kotlinx-coroutines-core-test/README.md) &mdash; coroutines test utilities such as Main dispatcher injection.
910

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Module kotlinx-coroutines-core-test
2+
3+
Test utilities for `kotlinx.coroutines`. Provides `MainDispatcherInjector.inject` to override `Main` dispatcher.
4+
5+
## Using in your project
6+
7+
Add `kotlinx-coroutines-core-test` to your project test dependencies:
8+
```
9+
dependencies {
10+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-test:1.0.0-RC1'
11+
}
12+
```
13+
14+
**Do not** depend on this project in your main sources, all utilities are intended and designed to be used only from tests.
15+
16+
Once you have it in runtime, [`ServiceLoader`](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) mechanism will
17+
overwrite [Dispatchers.Main] will injectable implementation, which uses `Dispatchers.Unconfined` default.
18+
19+
You can override this implementation using [inject][MainDispatcherInjector.inject] method with any [CoroutineDispatcher] implementation, e.g.:
20+
21+
```kotlin
22+
23+
class SomeTest {
24+
25+
private val mainThreadSurrogate = newSingleThreadContext("UI thread")
26+
27+
@Before
28+
fun setUp() {
29+
MainDispatcherInjector.inject(mainThreadSurrogate)
30+
}
31+
32+
@After
33+
fun tearDown() {
34+
MainDispatcherInjector.reset() // reset main dispatcher to Unconfined
35+
mainThreadSurrogate.close()
36+
}
37+
38+
@Test
39+
fun testSomeUI() = runBlocking {
40+
launch(Dispatchers.Main) {
41+
...
42+
}
43+
}
44+
}
45+
```
46+
47+
<!--- MODULE kotlinx-coroutines-core -->
48+
<!--- INDEX kotlinx.coroutines -->
49+
[Dispatchers.Main]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-dispatchers/-main.html
50+
[CoroutineDispatcher]: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-dispatcher/index.html
51+
<!--- END -->

knit/resources/knit.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
site.root=https://kotlin.github.io/kotlinx.coroutines
66

7-
module.roots=common js core integration native reactive ui
7+
module.roots=common js core core-test integration native reactive ui
88
module.marker=build.gradle
99
module.docs=build/dokka

0 commit comments

Comments
 (0)