@@ -407,6 +407,71 @@ public ProcessorBuilder<T, R> onError(Consumer<Throwable> errorHandler) {
407
407
return addStage (new Stage .OnError (errorHandler ));
408
408
}
409
409
410
+ /**
411
+ * Returns a stream containing all the elements from this stream. Additionally, in the case of failure, rather than
412
+ * invoking {@link #onError(Consumer)}, it invokes the given method and emits the result as final event of the stream.
413
+ *
414
+ * By default, when a stream encounters an error that prevents it from emitting the expected item to its subscriber,
415
+ * the stream (publisher) invokes its subscriber's <code>onError</code> method, and then terminate without invoking
416
+ * any more of its subscriber's methods. This operator changes this behavior. If the current stream encounters an
417
+ * error, instead of invoking its subscriber's <code>onError</code> method, it will instead emit the return value of
418
+ * the passed function. This operator prevents errors from propagating or to supply fallback data should errors be
419
+ * encountered.
420
+ *
421
+ * @param errorHandler the function returning the value that need to be emitting instead of the error.
422
+ * The function must not return {@code null}
423
+ * @return The new processor
424
+ */
425
+ public ProcessorBuilder <T , R > onErrorResume (Function <Throwable , R > errorHandler ) {
426
+ return addStage (new Stage .OnErrorResume (errorHandler ));
427
+ }
428
+
429
+ /**
430
+ * Returns a stream containing all the elements from this stream. Additionally, in the case of failure, rather than
431
+ * invoking {@link #onError(Consumer)}, it invokes the given method and emits the returned {@link PublisherBuilder}
432
+ * instead.
433
+ *
434
+ * By default, when a stream encounters an error that prevents it from emitting the expected item to its subscriber,
435
+ * the stream (publisher) invokes its subscriber's <code>onError</code> method, and then terminate without invoking
436
+ * any more of its subscriber's methods. This operator changes this behavior. If the current stream encounters an
437
+ * error, instead of invoking its subscriber's <code>onError</code> method, it will instead relinquish control to the
438
+ * {@link PublisherBuilder} returned from given function, which invoke the subscriber's <code>onNext</code> method if
439
+ * it is able to do so. In such a case, because no publisher necessarily invokes <code>onError</code>, the subscriber
440
+ * may never know that an error happened.
441
+ *
442
+ * @param errorHandler the function returning the stream that need to be emitting instead of the error.
443
+ * The function must not return {@code null}
444
+ * @return The new processor
445
+ */
446
+ public ProcessorBuilder <T , R > onErrorResumeWith (Function <Throwable , PublisherBuilder <R >> errorHandler ) {
447
+ return addStage (new Stage .OnErrorResumeWith (errorHandler .andThen (PublisherBuilder ::toGraph )));
448
+ }
449
+
450
+ /**
451
+ * Returns a stream containing all the elements from this stream. Additionally, in the case of failure, rather than
452
+ * invoking {@link #onError(Consumer)}, it invokes the given method and emits the returned {@link PublisherBuilder}
453
+ * instead.
454
+ *
455
+ * By default, when a stream encounters an error that prevents it from emitting the expected item to its subscriber,
456
+ * the stream (publisher) invokes its subscriber's <code>onError</code> method, and then terminate without invoking
457
+ * any more of its subscriber's methods. This operator changes this behavior. If the current stream encounters an
458
+ * error, instead of invoking its subscriber's <code>onError</code> method, it will instead relinquish control to the
459
+ * {@link PublisherBuilder} returned from given function, which invoke the subscriber's <code>onNext</code> method if
460
+ * it is able to do so. In such a case, because no publisher necessarily invokes <code>onError</code>, the subscriber
461
+ * may never know that an error happened.
462
+ *
463
+ * @param errorHandler the function returning the stream that need to be emitting instead of the error.
464
+ * The function must not return {@code null}
465
+ * @return The new processor
466
+ */
467
+ public ProcessorBuilder <T , R > onErrorResumeWithPublisher (Function <Throwable , Publisher <R >> errorHandler ) {
468
+ return addStage (new Stage .OnErrorResumeWith (
469
+ errorHandler
470
+ .andThen (ReactiveStreams ::fromPublisher )
471
+ .andThen (PublisherBuilder ::toGraph ))
472
+ );
473
+ }
474
+
410
475
/**
411
476
* Returns a stream containing all the elements from this stream, additionally performing the provided action when this
412
477
* stream completes or failed. The given action does not know if the stream failed or completed. If you need to
0 commit comments