File tree Expand file tree Collapse file tree 2 files changed +51
-8
lines changed
java8/src/main/java/org/jetbrains/annotations Expand file tree Collapse file tree 2 files changed +51
-8
lines changed Original file line number Diff line number Diff line change 2222 * Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
2323 * allows blocking methods execution.
2424 *
25- * If a given context does not allow blocking calls, {@link NonBlockingExecutor} should be used.
25+ * If a given executor does not allow blocking calls, {@link NonBlockingExecutor} should be used.
2626 *
27- * Example:
27+ * Example 1 (Kotlin coroutines) :
2828 * <pre>
2929 * {@code
30- * class ExampleService {
31- * @BlockingContext
30+ * class BlockingExampleService {
31+ * @BlockingExecutor
3232 * val dispatcher: CoroutineContext
3333 * get() { ... }
3434 *
4242 * }
4343 * }
4444 * </pre>
45+ *
46+ * Example 2 (Java with Reactor framework):
47+ * <pre>
48+ * {@code
49+ * class BlockingExampleService {
50+ * private static final @BlockingExecutor Scheduler blockingScheduler =
51+ * Schedulers.newBoundedElastic(4, 10, "executor");
52+ *
53+ * public Flux<String> foo(Flux<String> urls) {
54+ * return urls.publishOn(blockingScheduler)
55+ * .map(url -> blockingBuzz(url)); // no IDE warning
56+ * }
57+ *
58+ * @Blocking
59+ * private String blockingBuzz(String url) { ... }
60+ * }
61+ * }
62+ * </pre>
63+ *
64+ * @see Blocking
65+ * @see NonBlocking
4566 */
4667@ Documented
4768@ Retention (RetentionPolicy .CLASS )
Original file line number Diff line number Diff line change 2222 * Indicates that the annotated executor (e.g. coroutine dispatcher, scheduler, etc.)
2323 * does not allow blocking methods execution.
2424 *
25- * If a given context allows blocking calls, {@link BlockingExecutor} should be used.
25+ * If a given executor allows blocking calls, {@link BlockingExecutor} should be used.
2626 *
27- * Example:
27+ * Example 1 (Kotlin coroutines) :
2828 * <pre>
2929 * {@code
30- * class ExampleService {
31- * @NonBlockingContext
30+ * class NonBlockingExampleService {
31+ * @NonBlockingExecutor
3232 * val dispatcher: CoroutineContext
3333 * get() { ... }
3434 *
4242 * }
4343 * }
4444 * </pre>
45+ *
46+ * <br>
47+ * Example 2 (Java with Reactor framework):
48+ * <pre>
49+ * {@code
50+ * class NonBlockingExampleService {
51+ * private static final @NonBlockingExecutor Scheduler operationsScheduler =
52+ * Schedulers.newParallel("parallel");
53+ *
54+ * public Flux<String> foo(Flux<String> urls) {
55+ * return urls.publishOn(operationsScheduler)
56+ * .filter(url -> blockingBuzz(url) != null); // IDE warning: `Possibly blocking call in non-blocking context`
57+ * }
58+ *
59+ * @Blocking
60+ * private String blockingBuzz(String url) { ... }
61+ * }
62+ * }
63+ * </pre>
64+ *
65+ * @see Blocking
66+ * @see NonBlocking
4567 */
4668@ Documented
4769@ Retention (RetentionPolicy .CLASS )
You can’t perform that action at this time.
0 commit comments