const kv = await Deno.openKv();
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
console.log('I am in a web worker');
await increment("key2")
await listAll();
} else {
console.log('I am NOT in a web worker');
await increment("key1")
await listAll();
new Worker(import.meta.url, { type: "module" });
}
async function increment(key: string) {
const current = await kv.get([key]);
await kv.atomic().check(current).set([key], (current.value as number ?? 0) + 1).commit();
}
async function listAll(){
for await (const entry of kv.list({ prefix: [] })) {
console.log(entry);
}
}
const kv = await Deno.openKv();
if (typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope) {
console.log('I am in a web worker');
await increment("key2")
await listAll();
} else {
console.log('I am NOT in a web worker');
await increment("key1")
await listAll();
new Worker(import.meta.url, { type: "module" });
}
async function increment(key: string) {
const current = await kv.get([key]);
await kv.atomic().check(current).set([key], (current.value as number ?? 0) + 1).commit();
}
async function listAll(){
for await (const entry of kv.list({ prefix: [] })) {
console.log(entry);
}
}