Skip to content

Commit a846c37

Browse files
committed
~tweak Dokka and Knit, add integration test
1 parent 2bd85cc commit a846c37

File tree

6 files changed

+30
-74
lines changed

6 files changed

+30
-74
lines changed

README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ suspend fun main() = coroutineScope {
3737
* [core/jvm](kotlinx-coroutines-core/jvm/) — additional core features available on Kotlin/JVM:
3838
* [Dispatchers.IO] dispatcher for blocking coroutines;
3939
* [Executor.asCoroutineDispatcher][asCoroutineDispatcher] extension, custom thread pools, and more.
40+
* Integrations with [CompletableFuture] and JVM-specific extensions.
4041
* [core/js](kotlinx-coroutines-core/js/) — additional core features available on Kotlin/JS:
4142
* Integration with `Promise` via [Promise.await] and [promise] builder;
4243
* Integration with `Window` via [Window.asCoroutineDispatcher], etc.
@@ -56,7 +57,7 @@ suspend fun main() = coroutineScope {
5657
* [ui](ui/README.md) — modules that provide coroutine dispatchers for various single-threaded UI libraries:
5758
* Android, JavaFX, and Swing.
5859
* [integration](integration/README.md) — modules that provide integration with various asynchronous callback- and future-based libraries:
59-
* JDK8 [CompletionStage.await], Guava [ListenableFuture.await], and Google Play Services [Task.await];
60+
Guava [ListenableFuture.await], and Google Play Services [Task.await];
6061
* SLF4J MDC integration via [MDCContext].
6162

6263
## Documentation
@@ -259,9 +260,6 @@ See [Contributing Guidelines](CONTRIBUTING.md).
259260

260261
<!--- MODULE kotlinx-coroutines-jdk8 -->
261262
<!--- INDEX kotlinx.coroutines.future -->
262-
263-
[CompletionStage.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html
264-
265263
<!--- MODULE kotlinx-coroutines-guava -->
266264
<!--- INDEX kotlinx.coroutines.guava -->
267265

build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ def core_docs_url = "https://kotlinlang.org/api/kotlinx.coroutines/$coreModule/"
236236
def core_docs_file = "$projectDir/kotlinx-coroutines-core/build/dokka/htmlPartial/package-list"
237237
apply plugin: "org.jetbrains.dokka"
238238

239-
configure(subprojects.findAll { !unpublished.contains(it.name) && it.name != coreModule }) {
239+
configure(subprojects.findAll { !unpublished.contains(it.name)
240+
&& it.name != coreModule
241+
&& it.name != jdk8ObsoleteModule}) {
240242
if (it.name != 'kotlinx-coroutines-bom') {
241243
apply from: rootProject.file('gradle/dokka.gradle.kts')
242244
}
@@ -245,7 +247,7 @@ configure(subprojects.findAll { !unpublished.contains(it.name) && it.name != cor
245247

246248
configure(subprojects.findAll { !unpublished.contains(it.name) }) {
247249
if (it.name != "kotlinx-coroutines-bom") {
248-
if (it.name != coreModule) {
250+
if (it.name != coreModule && it.name != jdk8ObsoleteModule) {
249251
tasks.withType(DokkaTaskPartial.class) {
250252
dokkaSourceSets.configureEach {
251253
externalDocumentationLink {

buildSrc/src/main/kotlin/Projects.kt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fun Project.version(target: String): String =
88
property("${target}_version") as String
99

1010
val coreModule = "kotlinx-coroutines-core"
11+
val jdk8ObsoleteModule = "kotlinx-coroutines-jdk8"
1112
val testModule = "kotlinx-coroutines-test"
1213

1314
val multiplatform = setOf(coreModule, testModule)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
package kotlinx.coroutines
5+
6+
import kotlinx.coroutines.future.*
7+
import org.junit.Test
8+
import kotlin.test.*
9+
10+
/*
11+
* Temporary test that verifies both signatures from jdk8 and from core source-sets are used
12+
*/
13+
class Jdk8InCoreIntegration {
14+
15+
@Test
16+
fun testFuture() = runBlocking<Unit> {
17+
val future = future { yield(); 42 }
18+
future.whenComplete { r, _ -> assertEquals(42, r) }
19+
assertEquals(42, future.await())
20+
}
21+
}

integration/README.md

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

66
## Modules
77

8-
* [kotlinx-coroutines-jdk8](kotlinx-coroutines-jdk8/README.md) -- integration with JDK8 `CompletableFuture` (Android API level 24).
98
* [kotlinx-coroutines-guava](kotlinx-coroutines-guava/README.md) -- integration with Guava [ListenableFuture](https://github.com/google/guava/wiki/ListenableFutureExplained).
109
* [kotlinx-coroutines-slf4j](kotlinx-coroutines-slf4j/README.md) -- integration with SLF4J [MDC](https://logback.qos.ch/manual/mdc.html).
1110
* [kotlinx-coroutines-play-services](kotlinx-coroutines-play-services) -- integration with Google Play Services [Tasks API](https://developers.google.com/android/guides/tasks).
+2-67
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,3 @@
1-
# Module kotlinx-coroutines-jdk8
1+
# Stub module
22

3-
Integration with JDK8 [CompletableFuture] (Android API level 24).
4-
5-
Coroutine builders:
6-
7-
| **Name** | **Result** | **Scope** | **Description**
8-
| -------- | ------------------- | ---------------- | ---------------
9-
| [future] | [CompletableFuture] | [CoroutineScope] | Returns a single value with the future result
10-
11-
Extension functions:
12-
13-
| **Name** | **Description**
14-
| -------- | ---------------
15-
| [CompletionStage.await][java.util.concurrent.CompletionStage.await] | Awaits for completion of the completion stage
16-
| [CompletionStage.asDeferred][java.util.concurrent.CompletionStage.asDeferred] | Converts completion stage to an instance of [Deferred]
17-
| [Deferred.asCompletableFuture][kotlinx.coroutines.Deferred.asCompletableFuture] | Converts a deferred value to the future
18-
19-
## Example
20-
21-
Given the following functions defined in some Java API:
22-
23-
```java
24-
public CompletableFuture<Image> loadImageAsync(String name); // starts async image loading
25-
public Image combineImages(Image image1, Image image2); // synchronously combines two images using some algorithm
26-
```
27-
28-
We can consume this API from Kotlin coroutine to load two images and combine then asynchronously.
29-
The resulting function returns `CompletableFuture<Image>` for ease of use back from Java.
30-
31-
```kotlin
32-
fun combineImagesAsync(name1: String, name2: String): CompletableFuture<Image> = future {
33-
val future1 = loadImageAsync(name1) // start loading first image
34-
val future2 = loadImageAsync(name2) // start loading second image
35-
combineImages(future1.await(), future2.await()) // wait for both, combine, and return result
36-
}
37-
```
38-
39-
Note that this module should be used only for integration with existing Java APIs based on `CompletableFuture`.
40-
Writing pure-Kotlin code that uses `CompletableFuture` is highly not recommended, since the resulting APIs based
41-
on the futures are quite error-prone. See the discussion on
42-
[Asynchronous Programming Styles](https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md#asynchronous-programming-styles)
43-
for details on general problems pertaining to any future-based API and keep in mind that `CompletableFuture` exposes
44-
a _blocking_ method
45-
[get](https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html#get--)
46-
that makes it especially bad choice for coroutine-based Kotlin code.
47-
48-
# Package kotlinx.coroutines.future
49-
50-
Integration with JDK8 [CompletableFuture] (Android API level 24).
51-
52-
[CompletableFuture]: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html
53-
54-
<!--- MODULE kotlinx-coroutines-core -->
55-
<!--- INDEX kotlinx.coroutines -->
56-
57-
[CoroutineScope]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html
58-
[Deferred]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-deferred/index.html
59-
60-
<!--- MODULE kotlinx-coroutines-jdk8 -->
61-
<!--- INDEX kotlinx.coroutines.future -->
62-
63-
[future]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/future.html
64-
[java.util.concurrent.CompletionStage.await]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/await.html
65-
[java.util.concurrent.CompletionStage.asDeferred]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-deferred.html
66-
[kotlinx.coroutines.Deferred.asCompletableFuture]: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-jdk8/kotlinx.coroutines.future/as-completable-future.html
67-
68-
<!--- END -->
3+
Stub module for backwards compatibility. Since 1.7.0, this module was merged with core.

0 commit comments

Comments
 (0)