@Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); }
@Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); }
@Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); }
@Override public void call(SubjectObserver<T> o) { o.emitFirst(state.get(), state.nl); }
/** * Check if the Subject has terminated with an exception. * @return true if the subject has received a throwable through {@code onError}. */ @Experimental public boolean hasThrowable() { Object o = state.get(); return nl.isError(o); } /**
/** * Check if the Subject has terminated normally. * @return true if the subject completed normally via {@code onCompleted()} */ @Experimental public boolean hasCompleted() { Object o = state.get(); return nl.isCompleted(o); } /**
/** * Check if the Subject has a value. * <p>Use the {@link #getValue()} method to retrieve such a value. * <p>Note that unless {@link #hasCompleted()} or {@link #hasThrowable()} returns true, the value * retrieved by {@code getValue()} may get outdated. * @return true if and only if the subject has some value and hasn't terminated yet. */ @Experimental public boolean hasValue() { Object o = state.get(); return nl.isNext(o); } /**
@Override public void onCompleted() { Object last = state.get(); if (last == null || state.active) { Object n = nl.completed(); for (SubjectObserver<T> bo : state.terminate(n)) { bo.emitNext(n, state.nl); } } }
/** * Returns the Throwable that terminated the Subject. * @return the Throwable that terminated the Subject or {@code null} if the * subject hasn't terminated yet or it terminated normally. */ @Experimental public Throwable getThrowable() { Object o = state.get(); if (nl.isError(o)) { return nl.getError(o); } return null; } }
@Override public void onCompleted() { Object last = state.get(); if (last == null || state.active) { Object n = nl.completed(); for (SubjectObserver<T> bo : state.terminate(n)) { bo.emitNext(n, state.nl); } } }
@Override public void onError(Throwable e) { Object last = state.get(); if (last == null || state.active) { Object n = nl.error(e); for (SubjectObserver<T> bo : state.terminate(n)) { bo.emitNext(n, state.nl); } } }
@Override public void onNext(T v) { Object last = state.get(); if (last == null || state.active) { Object n = nl.next(v); for (SubjectObserver<T> bo : state.next(n)) { bo.emitNext(n, state.nl); } } }
@Override public void onNext(T v) { Object last = state.get(); if (last == null || state.active) { Object n = nl.next(v); for (SubjectObserver<T> bo : state.next(n)) { bo.emitNext(n, state.nl); } } }
@Override public void onError(Throwable e) { Object last = state.get(); if (last == null || state.active) { Object n = nl.error(e); List<Throwable> errors = null; for (SubjectObserver<T> bo : state.terminate(n)) { try { bo.emitNext(n, state.nl); } catch (Throwable e2) { if (errors == null) { errors = new ArrayList<Throwable>(); } errors.add(e2); } } Exceptions.throwIfAny(errors); } }
/** * Returns the current value of the Subject if there is such a value and * the subject hasn't terminated yet. * <p>The can return {@code null} for various reasons. Use {@link #hasValue()}, {@link #hasThrowable()} * and {@link #hasCompleted()} to determine if such {@code null} is a valid value, there was an * exception or the Subject terminated (with or without receiving any value). * @return the current value or {@code null} if the Subject doesn't have a value, * has terminated or has an actual {@code null} as a valid value. */ @Experimental public T getValue() { Object o = state.get(); if (nl.isNext(o)) { return nl.getValue(o); } return null; } /**
@Override public void call(SubjectObserver<T> o) { Object v = state.get(); NotificationLite<T> nl = state.nl; o.accept(v, nl); if (v == null || (!nl.isCompleted(v) && !nl.isError(v))) { o.onCompleted(); } } };