Skip to content

Commit 63506c7

Browse files
committed
doc(compiler): async函数支持第二个参数:CoroutineScope
1 parent 96996e2 commit 63506c7

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

compiler/suspend-transform-plugin/build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import com.bennyhuo.kotlin.plugin.embeddable.embeddableCompiler
2-
import com.bennyhuo.kotlin.plugin.embeddable.getOrCreate
3-
import com.bennyhuo.kotlin.plugin.embeddable.testWithEmbedded
4-
import embeddable.testWithEmbedded0
51
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
62

73
plugins {
@@ -19,6 +15,8 @@ plugins {
1915
dependencies {
2016
compileOnly(kotlin("stdlib"))
2117
compileOnly(kotlin("compiler"))
18+
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
19+
2220
// compileOnly(kotlin("compiler-embeddable"))
2321

2422
kapt("com.google.auto.service:auto-service:1.0.1")

compiler/suspend-transform-plugin/src/main/kotlin/love/forte/plugin/suspendtrans/SuspendTransformConfiguration.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,27 @@ open class SuspendTransformConfiguration @JvmOverloads constructor(var enabled:
5151
var jvmAsyncMarkAnnotation = MarkAnnotation(TO_JVM_ASYNC_ANNOTATION_NAME)
5252

5353
/**
54-
* 格式必须为
54+
* 格式必须为:
5555
*
5656
* ```kotlin
57-
* fun <T> <fun-name>(block: suspend () -> T): CompletableFuture<T> {
57+
* fun <T> <fun-name>(block: suspend () -> T[, scope: CoroutineScope = ...]): CompletableFuture<T> {
5858
* // ...
5959
* }
6060
* ```
61+
*
62+
* 其中,此异步函数可以有第二个参数,此参数格式必须为 [kotlinx.coroutines.CoroutineScope]。
63+
* 如果存在此参数,当转化函数所处类型自身实现了 [kotlinx.coroutines.CoroutineScope] 时,将会将其自身作为参数填入,类似于:
64+
*
65+
* ```kotlin
66+
* class Bar : CoroutineScope {
67+
* @JvmAsync
68+
* suspend fun foo(): Foo
69+
*
70+
* @Api4J fun fooAsync(): CompletableFuture<Foo> = runInAsync(block = { foo() }, scope = this)
71+
* }
72+
* ```
73+
* 当前类型不属于 [kotlinx.coroutines.CoroutineScope] 类型时不会使用此参数。
74+
*
6175
*/
6276
var jvmAsyncFunctionName: String = JVM_RUN_IN_ASYNC_FUNCTION_NAME
6377

0 commit comments

Comments
 (0)