I have a process that is basically part of a long polling implementation. In a nutshell, the client makes a request to the server, which then creates a channel and returns it to that client. The channel will contain the information that client asked for. Because this is intended to be used for long polling, the information that the client has requested can change. If the information changes, the server will write the update to the channel, and in theory, the client can grab the update and reflect that.
The problem I am facing is that there is a chance that I end up with tons of channels, which can cause unnecessary processing when an update occurs. I could potentially be updating channels where the client no longer cares.
My solution was that once the client stops caring about the information, it closes the channel, which will somehow notify the server, and prevent the server from doing additional processing and updates.
How can the server know if a channel is closed? In this scenario, the server is essentially a writer and does not read anything from the channel. Also, all the writing methods are wrapped in a go block, so it always returns a channel (I don't see any nils). Is there a way to do this, or is my approach completely off?
Thanks
The objectives of core.async are: To provide facilities for independent threads of activity, communicating via queue-like channels To support both real threads and shared use of thread pools (in any combination), as well as ClojureScript on JS engines
An async multi-producer multi-consumer channel, where each message can be received by only one of all existing consumers. Bounded channel with limited capacity. Unbounded channel with unlimited capacity. A channel has the Sender and Receiver side. Both sides are cloneable and can be shared among multiple threads.
Again, the Channel<Coordinates>.Writer is used within a while loop. But this time, the WriteAsync method is called. The method will continue only after the coordinates have been written. When the while loop exits, a call to Complete is made, which signals that no more data will be written to the channel.
This library is available in the System.Threading.Channels NuGet package (or included when targeting .NET Core 2.1+). Channels are an implementation of the producer/consumer conceptual programming model. In this programming model, producers asynchronously produce data, and consumers asynchronously consume that data.
As of earlier this year, there's a new feature called "putret" this change makes it so all put functions return false if the put fails due to the channel being closed. This allows for idioms like this:
(when (>! c val)
(recur (next itms)))
You can use clojure.core.async.impl.protocols/closed?
. As many thing in clojure core.async is 99% finished:)
IMO "producer side closures only" view is rather misleading. Producer could be dead or unresponsive or you might want to re-start your system, or parts of it, without recurring various alts!
obfuscating patterns with "stopping channels" etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With