Debian Codegraph @

src/org/jetbrains/annotations/NonBlockingExecutor.java

raw symbols SCIP
1 /*
2 * Copyright 2000-2021 JetBrains s.r.o.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.jetbrains.annotations;
18
19 import java.lang.annotation.*;
20
21 /**
22 * Indicates that the annotated executor (CoroutineContext, Scheduler)
23 * does not allow blocking methods execution.
24 *
25 * <p>
26 * If a given executor allows blocking calls, {@link BlockingExecutor} should be used.
27 *
28 * <p>
29 * Example 1 (Kotlin coroutines):
30 * <pre><code>
31 * class NonBlockingExampleService {
32 * val dispatcher: @NonBlockingExecutor 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 * &#064;Blocking fun blockingBuzz() { ... }
42 * }
43 * </code></pre>
44 *
45 * <p>
46 * Example 2 (Java with Reactor framework):
47 * <pre><code>
48 * class NonBlockingExampleService {
49 * private static final @NonBlockingExecutor Scheduler operationsScheduler =
50 * Schedulers.newParallel("parallel");
51 *
52 * public Flux&lt;String&gt; foo(Flux&lt;String&gt; urls) {
53 * return urls.publishOn(operationsScheduler)
54 * .filter(url -&gt; blockingBuzz(url) != null); // IDE warning: `Possibly blocking call in non-blocking context`
55 * }
56 *
57 * &#064;Blocking
58 * private String blockingBuzz(String url) { ... }
59 * }
60 * </code></pre>
61 * @see Blocking
62 * @see NonBlocking
63 */
64 @Documented
65 @Retention(RetentionPolicy.CLASS)
66 @Target({ElementType.TYPE, ElementType.TYPE_USE})
67 public @interface NonBlockingExecutor {
68 }