eli
eli
DDeno
Created by eli on 11/20/2024 in #help
Dynamic KV queue listener removal
It is possible to add listeners dynamically, but it seems impossible to remove them. I am creating listeners dynamically to process incoming messages from incoming WebSocket events. Each WebSocket client has an ID, and I want to create a queue dynamically for each ID when it connects, then process items in each queue sequentially to avoid concurrency issues arising from multiple rapid messages being received from the same client. However, if the connection is lost, I will need to create a new listener with a new WebSocket instance, so it can continue to process messages on the new connection. If I cannot remove the previous listener for this ID, I guess it will keep firing but be unable to send messages with its now stale WebSocket connection. Addding a listener currently returns void, but a convention I've seen is that adding listeners returns a function for removing them later. It seems like a good pattern to me. Would you consider it?
1 replies
DDeno
Created by eli on 11/20/2024 in #help
kv#listenQueue logs ""KV Connect does not support queues" and errors when the listener is triggered
The error is:
error: Uncaught (in promise) Error: Enqueue operations are not supported in KV Connect.
await kv.enqueue(incoming);
^
at doAtomicWriteInPlace (ext:deno_kv/01_db.ts:629:16)
at Kv.enqueue (ext:deno_kv/01_db.ts:163:32)
error: Uncaught (in promise) Error: Enqueue operations are not supported in KV Connect.
await kv.enqueue(incoming);
^
at doAtomicWriteInPlace (ext:deno_kv/01_db.ts:629:16)
at Kv.enqueue (ext:deno_kv/01_db.ts:163:32)
2 replies