Skip to content

Commit e1c0b65

Browse files
committed
MPP: Job/launch and related basic interface are extracted; JS basic impl
1 parent dadd50c commit e1c0b65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2727
-142
lines changed

build.gradle

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,30 @@ def pomConfig = {
5151

5252
def sourceless = ['site']
5353

54+
static def platformOf(project) {
55+
if (project.name.endsWith("-common")) return "common"
56+
if (project.name.endsWith("-js")) return "js"
57+
return "jvm"
58+
}
59+
60+
static def platformLib(base, platform) {
61+
if (platform == "jvm") return base
62+
return "$base-$platform"
63+
}
64+
5465
configure(subprojects.findAll { !sourceless.contains(it.name) }) {
55-
apply plugin: 'kotlin'
66+
def platform = platformOf(it)
67+
apply plugin: "kotlin-platform-$platform"
68+
69+
if (platform == "jvm") {
70+
sourceCompatibility = 1.6
71+
targetCompatibility = 1.6
5672

57-
sourceCompatibility = 1.6
58-
targetCompatibility = 1.6
59-
60-
tasks.withType(JavaCompile) {
61-
options.encoding = 'UTF-8'
73+
tasks.withType(JavaCompile) {
74+
options.encoding = 'UTF-8'
75+
}
6276
}
63-
77+
6478
kotlin.experimental.coroutines "enable"
6579

6680
tasks.withType(Test) {
@@ -75,8 +89,10 @@ configure(subprojects.findAll { !sourceless.contains(it.name) }) {
7589
maven { url "https://dl.bintray.com/devexperts/Maven/" }
7690
}
7791

92+
def kotlin_stdlib = platformLib("kotlin-stdlib", platform)
93+
7894
dependencies {
79-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
95+
compile "org.jetbrains.kotlin:$kotlin_stdlib:$kotlin_version"
8096
testCompile "junit:junit:$junit_version"
8197
}
8298
}
@@ -85,7 +101,8 @@ configure(subprojects.findAll { !sourceless.contains(it.name) }) {
85101

86102
def internal = sourceless + ['benchmarks', 'knit']
87103

88-
configure(subprojects.findAll { !internal.contains(it.name) }) {
104+
// configure atomicfu for JVM modules
105+
configure(subprojects.findAll { !internal.contains(it.name) && platformOf(it) == "jvm" }) {
89106
apply plugin: 'kotlinx-atomicfu'
90107

91108
dependencies {
@@ -110,11 +127,21 @@ configure(subprojects.findAll { !internal.contains(it.name) }) {
110127
}
111128
}
112129

113-
configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotlinx-coroutines-core'}) {
114-
dependencies {
115-
compile project(':kotlinx-coroutines-core')
116-
//the only way IDEA can resolve test classes
117-
testCompile project(':kotlinx-coroutines-core').sourceSets.test.output
130+
// configure dependencies on core
131+
configure(subprojects.findAll { !internal.contains(it.name) && it.name != 'kotlinx-coroutines-core-common'}) {
132+
def platform = platformOf(it)
133+
def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
134+
135+
if (it.name == coroutines_core) {
136+
dependencies {
137+
expectedBy project(':kotlinx-coroutines-core-common')
138+
}
139+
} else {
140+
dependencies {
141+
compile project(":$coroutines_core")
142+
//the only way IDEA can resolve test classes
143+
testCompile project(":$coroutines_core").sourceSets.test.output
144+
}
118145
}
119146
}
120147

@@ -126,6 +153,8 @@ def core_docs_url = "https://kotlin.github.io/kotlinx.coroutines/kotlinx-corouti
126153
def core_docs_file = "$projectDir/core/kotlinx-coroutines-core/build/dokka/kotlinx-coroutines-core/package-list"
127154

128155
configure(subprojects.findAll { !unpublished.contains(it.name) }) {
156+
def platform = platformOf(it)
157+
129158
apply plugin: 'maven'
130159
apply plugin: 'maven-publish'
131160
apply plugin: 'org.jetbrains.dokka'
@@ -135,9 +164,23 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
135164
outputFormat = 'kotlin-website'
136165
}
137166

138-
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
139-
outputFormat = 'javadoc'
140-
outputDirectory = "$buildDir/javadoc"
167+
if (platform == "jvm") {
168+
// real xxx-javadoc.jar for JVM
169+
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
170+
outputFormat = 'javadoc'
171+
outputDirectory = "$buildDir/javadoc"
172+
}
173+
174+
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
175+
classifier = 'javadoc'
176+
from "$buildDir/javadoc"
177+
}
178+
} else {
179+
// empty xxx-javadoc.jar
180+
task javadocJar(type: Jar) {
181+
classifier = 'javadoc'
182+
from "$buildDir/javadoc" // would not exist
183+
}
141184
}
142185

143186
tasks.withType(org.jetbrains.dokka.gradle.DokkaTask) {
@@ -151,11 +194,6 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
151194
}
152195
}
153196

154-
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
155-
classifier = 'javadoc'
156-
from "$buildDir/javadoc"
157-
}
158-
159197
task sourcesJar(type: Jar, dependsOn: classes) {
160198
classifier = 'sources'
161199
from sourceSets.main.allSource
@@ -199,9 +237,14 @@ configure(subprojects.findAll { !unpublished.contains(it.name) }) {
199237
}
200238
}
201239

202-
configure(subprojects.findAll { !unpublished.contains(it.name) && it.name != 'kotlinx-coroutines-core' }) {
203-
dokka.dependsOn project(':kotlinx-coroutines-core').dokka
204-
dokkaJavadoc.dependsOn project(':kotlinx-coroutines-core').dokka
240+
configure(subprojects.findAll { !unpublished.contains(it.name) && it.name != 'kotlinx-coroutines-core-common' }) {
241+
def platform = platformOf(it)
242+
def coroutines_core = platformLib("kotlinx-coroutines-core", platform)
243+
244+
dokka.dependsOn project(":$coroutines_core").dokka
245+
if (platform == "jvm") {
246+
dokkaJavadoc.dependsOn project(":$coroutines_core").dokka
247+
}
205248

206249
tasks.withType(org.jetbrains.dokka.gradle.DokkaTask) {
207250
externalDocumentationLink {

common/kotlinx-coroutines-core-common/build.gradle

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.CoroutineContext
4+
5+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
6+
public expect fun launch(
7+
context: CoroutineContext = DefaultDispatcher,
8+
start: CoroutineStart = CoroutineStart.DEFAULT,
9+
parent: Job? = null,
10+
block: suspend CoroutineScope.() -> Unit
11+
): Job
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.Continuation
4+
5+
public expect interface CancellableContinuation<in T> : Continuation<T> {
6+
public val isActive: Boolean
7+
public val isCompleted: Boolean
8+
public val isCancelled: Boolean
9+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
10+
public fun tryResume(value: T, idempotent: Any? = null): Any?
11+
public fun completeResume(token: Any)
12+
public fun initCancellability()
13+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
14+
public actual fun cancel(cause: Throwable? = null): Boolean
15+
public fun invokeOnCompletion(handler: CompletionHandler): DisposableHandle
16+
public fun CoroutineDispatcher.resumeUndispatched(value: T)
17+
public fun CoroutineDispatcher.resumeUndispatchedWithException(exception: Throwable)
18+
}
19+
20+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
21+
public expect suspend fun <T> suspendCancellableCoroutine(
22+
holdCancellability: Boolean = false,
23+
block: (CancellableContinuation<T>) -> Unit
24+
): T
25+
26+
@Suppress("EXPECTED_DECLARATION_WITH_DEFAULT_PARAMETER")
27+
public expect suspend fun <T> suspendAtomicCancellableCoroutine(
28+
holdCancellability: Boolean = false,
29+
block: (CancellableContinuation<T>) -> Unit
30+
): T
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package kotlinx.coroutines.experimental
2+
3+
/**
4+
* Handler for [Job.invokeOnCompletion].
5+
*
6+
* Installed handler should not throw any exceptions. If it does, they will get caught,
7+
* wrapped into [CompletionHandlerException], and rethrown, potentially causing crash of unrelated code.
8+
*
9+
* **Note**: This type is a part of internal machinery that supports parent-child hierarchies
10+
* and allows for implementation of suspending functions that wait on the Job's state.
11+
* This type should not be used in general application code.
12+
* Implementations of `CompletionHandler` must be fast and _lock-free_.
13+
*/
14+
public typealias CompletionHandler = (cause: Throwable?) -> Unit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.CoroutineContext
4+
5+
public expect object Unconfined : CoroutineDispatcher {
6+
override fun isDispatchNeeded(context: CoroutineContext): Boolean
7+
override fun dispatch(context: CoroutineContext, block: Runnable)
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.ContinuationInterceptor
4+
import kotlin.coroutines.experimental.CoroutineContext
5+
6+
public expect abstract class CoroutineDispatcher : ContinuationInterceptor {
7+
public open fun isDispatchNeeded(context: CoroutineContext): Boolean
8+
public abstract fun dispatch(context: CoroutineContext, block: Runnable)
9+
}
10+
11+
public expect interface Runnable {
12+
public fun run()
13+
}
14+
15+
@Suppress("PropertyName")
16+
public expect val DefaultDispatcher: CoroutineDispatcher
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.CoroutineContext
4+
5+
public expect fun handleCoroutineException(context: CoroutineContext, exception: Throwable)
6+
7+
public expect interface CoroutineExceptionHandler : CoroutineContext.Element {
8+
public companion object Key : CoroutineContext.Key<CoroutineExceptionHandler>
9+
public fun handleException(context: CoroutineContext, exception: Throwable)
10+
}
11+
12+
@Suppress("FunctionName")
13+
public expect fun CoroutineExceptionHandler(handler: (CoroutineContext, Throwable) -> Unit): CoroutineExceptionHandler
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.CoroutineContext
4+
5+
public expect interface CoroutineScope {
6+
public val isActive: Boolean
7+
public val coroutineContext: CoroutineContext
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kotlinx.coroutines.experimental
2+
3+
import kotlin.coroutines.experimental.Continuation
4+
5+
public expect enum class CoroutineStart {
6+
DEFAULT,
7+
LAZY,
8+
ATOMIC,
9+
UNDISPATCHED;
10+
public operator fun <T> invoke(block: suspend () -> T, completion: Continuation<T>)
11+
public operator fun <R, T> invoke(block: suspend R.() -> T, receiver: R, completion: Continuation<T>)
12+
public val isLazy: Boolean
13+
}

0 commit comments

Comments
 (0)