Skip to content

Commit eb6bf84

Browse files
committed
Implement Job() pseudo-constructor with top-level function
1 parent 8e2ae99 commit eb6bf84

File tree

1 file changed

+11
-3
lines changed
  • kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental

1 file changed

+11
-3
lines changed

kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/Job.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import kotlin.coroutines.experimental.CoroutineContext
3838
* or completion of parent immediately cancels all its children.
3939
*
4040
* The most basic instances of [Job] are created with [launch] coroutine builder or with a
41-
* [`Job()`][Job.Key.invoke] factory function. Other coroutine builders and primitives like
41+
* `Job()` factory function. Other coroutine builders and primitives like
4242
* [Deferred] also implement [Job] interface.
4343
*
4444
* A job has the following states:
@@ -57,7 +57,7 @@ import kotlin.coroutines.experimental.CoroutineContext
5757
*
5858
* A job can be _cancelled_ at any time with [cancel] function that forces it to transition to
5959
* _cancelling_ state immediately. Simple jobs, that are not backed by a coroutine, like
60-
* [CompletableDeferred] and the result of [`Job()`][Job.Key.invoke] factory function, don't
60+
* [CompletableDeferred] and the result of `Job()` factory function, don't
6161
* have a _cancelling_ state, but become _cancelled_ on [cancel] immediately.
6262
* Coroutines, on the other hand, become _cancelled_ only when they finish executing their code.
6363
*
@@ -92,8 +92,10 @@ public interface Job : CoroutineContext.Element {
9292
/**
9393
* Creates a new job object in _active_ state.
9494
* It is optionally a child of a [parent] job.
95+
* @suppress **Deprecated**
9596
*/
96-
public operator fun invoke(parent: Job? = null): Job = JobImpl(parent)
97+
@Deprecated("Replaced with top-level function", level = DeprecationLevel.HIDDEN)
98+
public operator fun invoke(parent: Job? = null): Job = Job(parent)
9799
}
98100

99101
// ------------ state query ------------
@@ -251,6 +253,12 @@ public interface Job : CoroutineContext.Element {
251253
}
252254
}
253255

256+
/**
257+
* Creates a new job object in an _active_ state.
258+
* It is optionally a child of a [parent] job.
259+
*/
260+
public fun Job(parent: Job? = null): Job = JobImpl(parent)
261+
254262
/**
255263
* A handle to an allocated object that can be disposed to make it eligible for garbage collection.
256264
*/

0 commit comments

Comments
 (0)