Skip to content

hekonsek/rxjava-failable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RxJava Failable

Version Build Coverage

RxJava Failable provides constructs for handling RxJava processing exceptions without interrupting continuous stream.

Installation

In order to start using Vert.x Failable add the following dependency to your Maven project:

<dependency>
  <groupId>com.github.hekonsek</groupId>
  <artifactId>rxjava-failable</artifactId>
  <version>0.3</version>
</dependency>

Usage

The following example demonstrates how to create callback invoked whenever flat map block throws an exception:

import static com.github.hekonsek.rxjava.failable.FailableFlatMap.failableFlatMap;

...

Observable.just(0, 1, 2, 4).
  compose(
    failableFlatMap(i -> just(4/i), (cause, value) -> {
      System.out.print("Error " + cause.getClass().getSimpleName());
      System.out.println(" for value: " + value);
    })
  ).subscribe(System.out::println);

The snippet above displays the following output:

Error ArithmeticException for value: 0
4
2
1

Please note that an invocation of a failure handles doesn't stop Observable from processing. What is also important, the original value processing of which caused the exception is sent to failure callback as well.

You can also use simplified syntax failable(...) instead of failableFlatMap(...). For example:

observable.compose(failable(i -> i, (cause, value) -> {}));

License

This project is distributed under Apache 2.0 license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published