fro.profesional
fro.profesional12mo ago

deno kv watch vs broadcast channel

For creating a chat app for example, which one should i use? What are the differences? Kv watch gets triggered even if no isolate is alive?
6 Replies
Deno AI Helper
Deno AI Helper12mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on your message, I can provide some general insights that might help you decide between Deno.KV.watch and BroadcastChannel. Deno.KV.watch is a feature that allows you to watch for changes on a given key in Deno's key-value storage. When a key is updated, a watcher can be notified of this change. This can be useful for synchronizing state across different parts of your application or across different instances of your application. On the other hand, BroadcastChannel is a web standard that allows you to broadcast messages to other scripts that are listening to the same channel. It's typically used for communication between different parts of a web application running in the same browser context, but it can also be used in workers or other environments that support it. For a chat application, you might find BroadcastChannel more suitable if your chat is confined to a single browser context or you are using web workers. It allows for easy message passing between different parts of your application without the need for a backend service to relay messages. Regarding your question about Deno.KV.watch being triggered even if no isolate is alive, I cannot provide a definitive answer as this is not covered in the Deno documentation. However, it's important to note that Deno.KV.watch is likely designed to work with Deno's infrastructure, and its behavior would depend on how Deno's key-value storage is implemented and how it interacts with isolates. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of the advice given. For the most accurate and up-to-date information, you may want to explore
Deno AI Helper
Deno AI Helper12mo ago
the Deno community resources or reach out to the Deno maintainers directly.
Antonio Sampaio
Antonio Sampaio12mo ago
I saw some messages about kv.watch not notifying all events, only the last ones
fro.profesional
fro.profesionalOP11mo ago
I saw some mention in #deploy™ that BroadcastChannel messages doesn’t have guaranteed delivery and kv watch does so I guess for a chat is better kv watch all though I don’t think there are exclusive (can be used and the same time i think)
CI010
CI0103mo ago
echo fro's post. The BroadcastChannel is not reliable. I've created an deno deploy app to exchange webrtc's description between peers, and sometime the message is not delivered (user cannot get the descriptor from other peers, even i send the same message multiple times). Currently, im rewriting my deno deploy server using the deno kv which can ensure the delivery.
Fifth-Normal-Form
Many moons ago -- pre KV -- I also used BroadcastChannel for webrtc signaling in Deploy for a multi-user dice game. It worked very well back then. I think post KV it was somehow crippled.