question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to drop some object (temporary disconnect) when there is pending operation.

See original GitHub issue

Hello I have a question. Sometimes I want to send an http request when a button is pressed but I don’t want to send too much http request I just want to drop any button press emission when there is a pending http request.

I attempt with a couple solution with some flaw.

Attempt 1 Solution: use onBackpressureDrop and use reactive pull Subscriber as parameter to subscribe(). Issue: This solution require some code implementation in subscriber instance the problem is onBackpressureDrop and subscriber code is too far away from each other (different file). Make it hard to reasoning why the Subscriber instance implement the way it is. This approach will be perfect if I can move reactive pull up the chain. e.g.

Observable buttonPress;
Func1 sendHttpRequest;
buttonPress.onBackpressureDrop().flatMap(sendHttpRequest).[ *** request(1) Operation *** ]

Basically the same as reactive pull but instead of doing it in subscriber do it with some operator inside transformation chain. I simply don’t know such method (or operator) if you know how can I archive the same effect please tell me.

Attempt 2 Solution: use ConnectableObservable to temporary disconnect flatMap operation from source. Issue: So imparative and the actual code looks bad break the purpose of using reactive paradigm. I might did it the wrong way if you have an example to bring this idea into practice I will be very glad to see your example.

If you think both of my attempt are not even close to simple implementation available out of the box. I will be happy to see your suggestion on the original issue.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
abersnazecommented, Mar 24, 2016

The real world use for debounce is interactive search box where you don’t want every key press to cause a http call to a search service.

onTextBoxChange().debounce(100 ms).switchMap(text -> search(text)).subscribe(updateResults)

I’m thinking the reason it doesn’t work for you is that I’m assuming you don’t want to cancel an in flight request if the user give you more input because the operation is not idempotent.

1reaction
abersnazecommented, Mar 24, 2016

Check out debounce() there are three flavors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure AD Connect sync: Prevent accidental deletes
What is prevent accidental deletes · Start Synchronization Service from the Start Menu. · Go to Connectors. · Select the Connector with type...
Read more >
Db2 SQL - COMMIT - IBM
The declared global temporary table is defined with the ON COMMIT DROP TABLE option. The statement uses the RELEASE(COMMIT) bind option. The statement...
Read more >
Impact of temporary disconnection from Google Cloud
You use the bmctl or gkectl CLI tools to delete clusters. This operation does not require a connection to Google Cloud. You can...
Read more >
Containers - Fluid Framework
Some initial shared objects that are created as soon as the container is ... or disconnect the container while isDirty === true ,...
Read more >
WiFi Keeps Disconnecting All The Time? Here's How To Fix It
Being in an area with limited or no internet connection; WiFi driver isn't compatible with your the current version of your operating system ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found