Skip to content

Commit ec7d510

Browse files
Nikita KatkovNikita Katkov
authored andcommitted
Changed BlockingContext to BlockingExecutor and added example to javadoc
1 parent 9d771c0 commit ec7d510

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

java8/src/main/java/org/jetbrains/annotations/BlockingContext.java renamed to java8/src/main/java/org/jetbrains/annotations/BlockingExecutor.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,32 @@
1919
import java.lang.annotation.*;
2020

2121
/**
22-
* Indicates that the annotated execution context (e.g. coroutine dispatcher, scheduler, etc.) allows blocking calls inside.
22+
* Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
23+
* allows blocking methods execution.
24+
*
25+
* If a given context does not allow blocking calls, {@link NonBlockingExecutor} should be used.
26+
*
27+
* Example:
28+
* <pre>
29+
* {@code
30+
* class ExampleService {
31+
* @BlockingContext
32+
* val dispatcher: CoroutineContext
33+
* get() { ... }
34+
*
35+
* suspend fun foo() {
36+
* val result = withContext(dispatcher) {
37+
* blockingBuzz() // no IDE warning
38+
* }
39+
* }
40+
*
41+
* @Blocking fun blockingBuzz() { ... }
42+
* }
43+
* }
44+
* </pre>
2345
*/
2446
@Documented
2547
@Retention(RetentionPolicy.CLASS)
2648
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE_USE})
27-
public @interface BlockingContext {
49+
public @interface BlockingExecutor {
2850
}

java8/src/main/java/org/jetbrains/annotations/NonBlockingContext.java renamed to java8/src/main/java/org/jetbrains/annotations/NonBlockingExecutor.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,32 @@
1919
import java.lang.annotation.*;
2020

2121
/**
22-
* Indicates that the annotated execution context (e.g. coroutine dispatcher, scheduler, etc.) does not allow blocking calls inside.
22+
* Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
23+
* does not allow blocking methods execution.
24+
*
25+
* If a given context allows blocking calls, {@link BlockingExecutor} should be used.
26+
*
27+
* Example:
28+
* <pre>
29+
* {@code
30+
* class ExampleService {
31+
* @NonBlockingContext
32+
* val dispatcher: CoroutineContext
33+
* get() { ... }
34+
*
35+
* suspend fun foo() {
36+
* val result = withContext(dispatcher) {
37+
* blockingBuzz() // IDE warning: `Possibly blocking call in non-blocking context`
38+
* }
39+
* }
40+
*
41+
* @Blocking fun blockingBuzz() { ... }
42+
* }
43+
* }
44+
* </pre>
2345
*/
2446
@Documented
2547
@Retention(RetentionPolicy.CLASS)
2648
@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE_USE})
27-
public @interface NonBlockingContext {
49+
public @interface NonBlockingExecutor {
2850
}

0 commit comments

Comments
 (0)