in autodispose-lifecycle/src/main/java/autodispose2/lifecycle/LifecycleScopes.java [78:108]
public static <@NonNull E> CompletableSource resolveScopeFromLifecycle(
final LifecycleScopeProvider<E> provider, final boolean checkEndBoundary)
throws OutsideScopeException {
E lastEvent = provider.peekLifecycle();
CorrespondingEventsFunction<E> eventsFunction = provider.correspondingEvents();
if (lastEvent == null) {
throw new LifecycleNotStartedException();
}
E endEvent;
try {
endEvent = eventsFunction.apply(lastEvent);
} catch (Exception e) {
if (checkEndBoundary && e instanceof LifecycleEndedException) {
Consumer<? super OutsideScopeException> handler =
AutoDisposePlugins.getOutsideScopeHandler();
if (handler != null) {
try {
handler.accept((LifecycleEndedException) e);
// Swallowed the end exception, just silently dispose immediately.
return Completable.complete();
} catch (Throwable e1) {
return Completable.error(e1);
}
}
throw e;
}
return Completable.error(e);
}
return resolveScopeFromLifecycle(provider.lifecycle(), endEvent);
}