long-polling-redis | Example App showing client side long polling | Application Framework library
kandi X-RAY | long-polling-redis Summary
kandi X-RAY | long-polling-redis Summary
A naive approach to front-end querying of the backend for new emails, messages, alerts, etc. is to poll every x seconds. In Javascript, this is usually done using the setInterval() function. For example, if one were to design a email app similar to GMail, the user will expect new incoming messages to be shown in the inbox count automatically (i.e. without having to constantly refresh the page). Polling again and again is a waste of resources on both the client and server, especially when the frequency of polling is far greater than new incoming messages are received. A better way to approach the problem is by using async requests on a pubsub channel on the backend, along with a recursive function on the front-end that only makes new requests when the old has actually returned.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- generate a string in place .
- wraps around sh methods
- Creates an element and adds it to a document .
- Shows the shim document .
- Recursively revives values in a holder
- Return a clone of a document
- Escapes quotes around a string .
- Adds an array of elements
- Returns the data associated to the given document
- Adds a style element to the document
long-polling-redis Key Features
long-polling-redis Examples and Code Snippets
Community Discussions
Trending Discussions on long-polling-redis
QUESTION
I found this repository at GitHub Long Polling Redis
So in spring boot, we can use a deferred request to hold the client request for several seconds (AppMsgController.java#L72)
and it will send back to the client until the deferred request is filled with the result (AppMsgHandler.java#L74) or until it reaches the timeout.
I also notice this mechanism also can be implemented with CompetableFuture in java using completeOnTimeout.
But I wonder can we use something similar in Kotlin Coroutines?
...ANSWER
Answered 2022-Jan-18 at 11:26In Kotlin coroutines there is the Deferred
type, which is similar to CompletableFuture
in the sense that it represents a value that is not yet available but probably will be in the future (if no error occurs/exception is thrown). @Joffrey pointed out that there is also a CompletableDeferred
, which is even closer to ComplatableFuture
enabling the user to manually call complete
or exceptionallyComplete
.
Deferreds can easily be created with the async
extension function on CoroutineScope
. If you want to set a timeout, Kotlin has you covered with the withTimeout
function that cancels the block of code after a given time.
Note that withTimeout
should be inside async
and not the other way around.
Take a look at this example: https://pl.kotl.in/uYe12ds7g
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install long-polling-redis
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page