class CognitoIdentityProvider {

    @NonNull
    public Single<Optional<Cognito>> prefetchCognitoTokenIfNeeded() {
        return Single.fromCallable(this::getCachedCognitoToken)
                .flatMap(cognitoOptional -> {
                    if (!cognitoOptional.isPresent()
                            || cognitoOptional.get().getCognitoToken() == null
                            || cognitoOptional.get().getIdentityId() == null) {
                        Logger.debug(CognitoIdentityProvider.this, "Existing cognito token is invalid. Pre-fetching...");
                        return refreshCognitoToken();
                    } else {
                        Logger.debug(CognitoIdentityProvider.this, "Existing cognito token is valid");
                        return Single.just(cognitoOptional);
                    }
                });
    }

    @Inject public  CognitoIdentityProvider(@NonNull IdentityManager identityManager,
                                   @NonNull LocalCognitoTokenStore localCognitoTokenStore);

}