• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines
6 
7 /**
8  * A job that can be completed using [complete()] function.
9  * It is returned by [Job()][Job] and [SupervisorJob()][SupervisorJob] constructor functions.
10  *
11  * All functions on this interface are **thread-safe** and can
12  * be safely invoked from concurrent coroutines without external synchronization.
13  *
14  * **The `CompletableJob` interface is not stable for inheritance in 3rd party libraries**,
15  * as new methods might be added to this interface in the future, but is stable for use.
16  */
17 public interface CompletableJob : Job {
18     /**
19      * Completes this job. The result is `true` if this job was completed as a result of this invocation and
20      * `false` otherwise (if it was already completed).
21      *
22      * Subsequent invocations of this function have no effect and always produce `false`.
23      *
24      * This function transitions this job into _completed- state if it was not completed or cancelled yet.
25      * However, that if this job has children, then it transitions into _completing_ state and becomes _complete_
26      * once all its children are [complete][isCompleted]. See [Job] for details.
27      */
completenull28     public fun complete(): Boolean
29 
30     /**
31      * Completes this job exceptionally with a given [exception]. The result is `true` if this job was
32      * completed as a result of this invocation and `false` otherwise (if it was already completed).
33      * [exception] parameter is used as an additional debug information that is not handled by any exception handlers.
34      *
35      * Subsequent invocations of this function have no effect and always produce `false`.
36      *
37      * This function transitions this job into _cancelled_ state if it was not completed or cancelled yet.
38      * However, that if this job has children, then it transitions into _cancelling_ state and becomes _cancelled_
39      * once all its children are [complete][isCompleted]. See [Job] for details.
40      *
41      * Its responsibility of the caller to properly handle and report the given [exception], all job's children will receive
42      * a [CancellationException] with the [exception] as a cause for the sake of diagnostic.
43      */
44     public fun completeExceptionally(exception: Throwable): Boolean
45 }
46