google / google/volley

Rx and how to know if Request has completed

Open
#247 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.4k
Forks
751
Avg merge
8h 49m
Merged PRs (30d)
2

Description

When overriding a Request we have the power to override the following methods

* **deliverError**
* **deliverResponse**

I want to write a custom request that enables reactive programming. I want my request to emit values `onNext`, emit errors `onError` and emit completenes `onComplete`. My first attempt is the following code.

```java
@Override
public void deliverError(VolleyError error) {
super.deliverError(error);
this.emitter.onError(error);
this.emitter.onComplete();
}

@Override
protected void deliverResponse(R response) {
super.deliverResponse(response);
this.emitter.onNext(response);
// is this a cached response and there will be another network response
// or is it a network response and i can safely call onComplete()
this.onComplete();
}
```

Since `deliverResponse` is called for both cached and network responses and there is no way to distinguish between them (or is there?) we can not reliably call `onComplete` after delivery.

Maybe i am missing something.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.