Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Observable from UnityWebRequest calls OnComplete although status is still InProgress #530

Open
achimmihca opened this issue Feb 7, 2023 · 1 comment

Comments

@achimmihca
Copy link

achimmihca commented Feb 7, 2023

I do the following to observe a UnityWebRequest:

UnityWebRequest unityWebRequest = UnityWebRequest.Get(uri);

void OnNext()
{
    Debug.Log($"{unityWebRequest.method} '{unityWebRequest.uri}' has updated. Status: {unityWebRequest.result}, response code: {unityWebRequest.responseCode}");
}

void OnError
{
    Debug.LogError($"{unityWebRequest.method} '{unityWebRequest.uri}' has failed. Status: {unityWebRequest.result}, response code: {unityWebRequest.responseCode}, error message: {ex.Message}");
    Debug.LogException(ex);
}

void OnComplete()
{
    Debug.Log($"{unityWebRequest.method} '{unityWebRequest.uri}' has completed. Status: {unityWebRequest.result}, response code: {unityWebRequest.responseCode}, response body: {unityWebRequest.downloadHandler.text}");
}

unityWebRequest
    .SendWebRequest()
    .AsAsyncOperationObservable()
    .Subscribe(OnSucess, OnError, OnComplete);

My problem is that sometimes (not always) the OnComplete method is called although unityWebRequest.result is still InProgress, the unityWebRequest.downloadHandler.text is empty, and unityWebRequest.isDone is false.
Thus, OnComplete seems to be called prematurely sometimes.

Is this a bug?
Or do I have to create the Observable from the UnityWebRequest differently somehow?

@achimmihca
Copy link
Author

I noticed that there are

I think these would be obsolete if the above example would work as expected (i.e. OnComplete was not called prematurely)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant