summaryrefslogtreecommitdiff
path: root/ext/kv/01_db.ts
diff options
context:
space:
mode:
authorRaashid Anwar <raashid12anwar@gmail.com>2023-12-05 23:46:47 +0530
committerGitHub <noreply@github.com>2023-12-05 10:16:47 -0800
commitcac17267fbe83f25181c4f8503c01b92694c46be (patch)
tree213ee5a7a24f613455757f434fb501fe69f8ff6f /ext/kv/01_db.ts
parent4a9f42950140b36b1916ab0e0320d721223b1095 (diff)
fix(ext/kv): throw error if already closed (#21459)
If KV is closed and tries to listen queue should throw an error closes #20991
Diffstat (limited to 'ext/kv/01_db.ts')
-rw-r--r--ext/kv/01_db.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/ext/kv/01_db.ts b/ext/kv/01_db.ts
index 73deee27f..2b0e141f8 100644
--- a/ext/kv/01_db.ts
+++ b/ext/kv/01_db.ts
@@ -64,6 +64,7 @@ const kvSymbol = Symbol("KvRid");
class Kv {
#rid: number;
+ #isClosed: boolean;
constructor(rid: number = undefined, symbol: symbol = undefined) {
if (kvSymbol !== symbol) {
@@ -72,6 +73,7 @@ class Kv {
);
}
this.#rid = rid;
+ this.#isClosed = false;
}
atomic() {
@@ -251,6 +253,9 @@ class Kv {
async listenQueue(
handler: (message: unknown) => Promise<void> | void,
): Promise<void> {
+ if (this.#isClosed) {
+ throw new Error("already closed");
+ }
const finishMessageOps = new Map<number, Promise<void>>();
while (true) {
// Wait for the next message.
@@ -366,6 +371,7 @@ class Kv {
close() {
core.close(this.#rid);
+ this.#isClosed = true;
}
[SymbolDispose]() {