Structured concurrency implementation:
* Introducing async, launch, produce, actor and broadcast extensions on CoroutineScope
* Deprecate top-level coroutine builders
* Introducing currentScope and coroutineScope for manipulation with CoroutineScope interface
* Introducing CoroutineScope factories
* Introducing extension CoroutineScope.isActive
Fixes #410
diff --git a/common/kotlinx-coroutines-core-common/src/internal/Scopes.kt b/common/kotlinx-coroutines-core-common/src/internal/Scopes.kt
new file mode 100644
index 0000000..ee51615
--- /dev/null
+++ b/common/kotlinx-coroutines-core-common/src/internal/Scopes.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package kotlinx.coroutines.experimental.internal
+
+import kotlinx.coroutines.experimental.*
+import kotlin.coroutines.experimental.*
+
+internal class ScopeOwnerCoroutine<R>(
+ parentContext: CoroutineContext
+) : AbstractCoroutine<R>(parentContext, true), CoroutineScope {
+
+ override val coroutineContext: CoroutineContext = parentContext + this
+
+ /*
+ * Always return true, so final exception is in the scope before its completion.
+ */
+ override fun cancel(cause: Throwable?): Boolean {
+ super.cancel(cause)
+ return true
+ }
+}
+
+internal class ContextScope(context: CoroutineContext) : CoroutineScope {
+ override val coroutineContext: CoroutineContext = context
+}
+
+internal fun CoroutineScope.newCoroutineContext(context: CoroutineContext): CoroutineContext =
+ newCoroutineContext(coroutineContext + context, parent = null)