All Downloads are FREE. Search and download functionalities are using the official Maven repository.

se.fortnox.reactivewizard.client.ObservableWithResponse Maven / Gradle / Ivy

package se.fortnox.reactivewizard.client;

import reactor.netty.http.client.HttpClientResponse;
import rx.Observable;

import java.util.concurrent.atomic.AtomicReference;

/**
 * Internal class to help support getting the full response as return value when observable is returned
 * @param  the type of data to be returned
 */
class ObservableWithResponse extends Observable {

    private final AtomicReference httpClientResponse;

    ObservableWithResponse(Observable inner, AtomicReference httpClientResponse) {
        super(inner::unsafeSubscribe);
        this.httpClientResponse = httpClientResponse;
    }

    HttpClientResponse getResponse() {
        if (httpClientResponse.get() == null) {
            throw new IllegalStateException("This method can only be called after the response has been received");
        }
        return httpClientResponse.get();
    }

    static  ObservableWithResponse from(ObservableWithResponse observableWithResponse, Observable inner) {
        return new ObservableWithResponse(inner, observableWithResponse.httpClientResponse);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy