Debian Codegraph @

src/org/jetbrains/annotations/BlockingExecutor.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 * allows blocking methods execution.
24 * <p>
25 * If a given executor does not allow blocking calls, {@link NonBlockingExecutor} should be used.
26 *
27 * <p>
28 * Example 1 (Kotlin coroutines):
29 * <pre><code>
30 * class BlockingExampleService {
31 * val dispatcher: @BlockingExecutor CoroutineContext
32 * get() { ... }
33 *
34 * suspend fun foo() {
35 * val result = withContext(dispatcher) {
36 * blockingBuzz() // no IDE warning
37 * }
38 * }
39 *
40 * &#064;Blocking fun blockingBuzz() { ... }
41 * }
42 * </code></pre>
43 *
44 * <p>
45 * Example 2 (Java with Reactor framework):
46 * <pre><code>
47 * class BlockingExampleService {
48 * private static final @BlockingExecutor Scheduler blockingScheduler =
49 * Schedulers.newBoundedElastic(4, 10, "executor");
50 *
51 * public Flux&lt;String&gt; foo(Flux&lt;String&gt; urls) {
52 * return urls.publishOn(blockingScheduler)
53 * .map(url -&gt; blockingBuzz(url)); // no IDE warning
54 * }
55 *
56 * &#064;Blocking
57 * private String blockingBuzz(String url) { ... }
58 * }
59 * </code></pre>
60 *
61 * @see Blocking
62 * @see NonBlocking
63 */
64 @Documented
65 @Retention(RetentionPolicy.CLASS)
66 @Target({ElementType.TYPE, ElementType.TYPE_USE})
67 public @interface BlockingExecutor {
68 }