Annotation Type NonBlockingExecutor


  • @Documented
    @Retention(CLASS)
    @Target({TYPE,TYPE_USE})
    public @interface NonBlockingExecutor
    Indicates that the annotated executor (CoroutineContext, Scheduler) does not allow blocking methods execution.

    If a given executor allows blocking calls, BlockingExecutor should be used.

    Example 1 (Kotlin coroutines):

    
      class NonBlockingExampleService {
          val dispatcher: @NonBlockingExecutor CoroutineContext
              get() { ... }
    
          suspend fun foo() {
              val result = withContext(dispatcher) {
                  blockingBuzz() // IDE warning: `Possibly blocking call in non-blocking context`
              }
          }
    
          @Blocking fun blockingBuzz() { ... }
      }
     

    Example 2 (Java with Reactor framework):

    
      class NonBlockingExampleService {
          private static final @NonBlockingExecutor Scheduler operationsScheduler =
                  Schedulers.newParallel("parallel");
    
          public Flux<String> foo(Flux<String> urls) {
              return urls.publishOn(operationsScheduler)
                      .filter(url -> blockingBuzz(url) != null);  // IDE warning: `Possibly blocking call in non-blocking context`
          }
    
          @Blocking
          private String blockingBuzz(String url) { ... }
      }
     
    See Also:
    Blocking, NonBlocking