RxJava- If you are not using Observable?

I came across a script using RxJava, and I'm not quite sure whether to use Observable<T>either final ImmutableList<T>.

Basically, if I import a final and immutable dataset once and never again, should I really expose this as cold Observable<T>?

public final class StrategyManager {

    private static final StrategyManager instance = new StrategyManager();

    private final ImmutableList<Strategy> strategies;

    private StrategyManager() {
        strategies = //import from db
    }
    public Observable<Strategy> getStrategies() { 
        return Observable.from(strategies);
    }
    public static StrategyManager get() { 
        return instance;
    }
}

Or should I just show it how ImmutableList<T>?

public final class StrategyManager {

    private static final StrategyManager instance = new StrategyManager();

    private final ImmutableList<Strategy> strategies;

    private StrategyManager() {
        strategies = //import from db
    }
    public ImmutableList<Strategy> getStrategies() { 
        return strategies;
    }
    public static StrategyManager get() { 
        return instance;
    }
}

If I expose it as ImmutableList<T>, the customers have one smaller monad with which to deal with what will always be permanent.

, , Observable<T>. , RxJava-JDBC . cache() replay(), .

public final class StrategyManager {

    private static final StrategyManager instance = new StrategyManager();

    private final Observable<Strategy> strategies;

    private Database db = null;

    private StrategyManager() {
        strategies = db.select("SELECT * FROM STRATEGY")
                .autoMap(Strategy.class)
                .replay(1, TimeUnit.MINUTES)
                .autoConnect();
    }
    public Observable<Strategy> getStrategies() { 
        return strategies;
    }
    public static StrategyManager get() { 
        return instance;
    }
}

, : , Observable? , Observable , ? , ?

+4
1

. , , API "" "", , .

Observable , ?

, RxJava, ( RxJava), Observable. , " , " , .

, , - , Observables ( ), .

, , .

API Netflix ( ) .

+5

Source: https://habr.com/ru/post/1608135/


All Articles