@NonNull
    private static <T> ObservableTransformer<T, T> takeUntil(Observable<?> beforeEmission, Observable<?> afterEmission) {
        return observable -> observable.publish(publishedObservable -> {
                    final Observable<?> afterEmissionTakeUntil = publishedObservable
                            .take(1)
                            .ignoreElements()
                            .andThen(afterEmission);
                    return Observable.amb(
                            asList(
                                    publishedObservable,
                                    publishedObservable.takeUntil(beforeEmission)
                            ))
                            .takeUntil(afterEmissionTakeUntil);
                }
        );
    }
A convenience function creating a transformer that will use two observables for completing the returned observable (and
un-subscribing from the passed observable) beforeEmission will be used to complete the passed observable before it's first
emission and afterEmission will be used to do the same after the first emission

@param beforeEmission the observable that will control completing the returned observable before it's first emission
@param afterEmission  the observable that will control completing the returned observable after it's first emission
@param <T>            the type of the passed observable
@return the observable
sample/src/main/java/com/polidea/rxandroidble2/sample/example4_characteristic/advanced/Presenter.java