ataractic
ataractic•12mo ago

Getting values from Deno KV in a Web Worker always return empty array despite working correctly o...

Getting values from Deno KV in a Web Worker always return empty array despite working correctly outside the worker context (in the parent app). What can cause this behavior?
No description
14 Replies
fro.profesional
fro.profesional•12mo ago
Hmmm its reading from same db right? 🤔
ataractic
ataractic•12mo ago
yes
NDH
NDH•12mo ago
What does getAllJobs() look like?
ataractic
ataractic•12mo ago
export async function getAllJobs() {
return await getValues<Job>({ prefix: ["jobs"] });
}
export async function getAllJobs() {
return await getValues<Job>({ prefix: ["jobs"] });
}
NDH
NDH•12mo ago
I don't think I can help. I don't know what getValues<job> does. I assume at some point it's calling kv.list? Is the code in a public repo? Can we have a look?
ataractic
ataractic•12mo ago
yes sorry, here is getValues()
async function getValues<T>(
selector: Deno.KvListSelector,
options?: Deno.KvListOptions,
) {
const values = [];
const iter = kv.list<T>(selector, options);
for await (const { value } of iter) values.push(value);
return values;
}
async function getValues<T>(
selector: Deno.KvListSelector,
options?: Deno.KvListOptions,
) {
const values = [];
const iter = kv.list<T>(selector, options);
for await (const { value } of iter) values.push(value);
return values;
}
i use a lot of code from saaskit to help me
NDH
NDH•12mo ago
I have no experience with saaskit; sorry. Hopefully someone with experience will jump in to help you.
ataractic
ataractic•12mo ago
thanks you for trying :)
cknight
cknight•11mo ago
Have you tried Deno.openKv() in your worker?
fro.profesional
fro.profesional•11mo ago
That will create another db
iuioiua
iuioiua•11mo ago
Sidenote: I'd actually recommend instead using collectValues(). It allows you to use iter.cursor once the values are collected.
ataractic
ataractic•11mo ago
i will do it once it can at least work, thanks for the tip! i went with another approach, using message events to send job data both ways between the main thread to the worker, and it works! however i'm pretty sure it impacts performance pretty badly as compared to the first idea.
iuioiua
iuioiua•11mo ago
Actually, check SaaSKit out once v1 is released. We’ll have some noteworthy bits of the KV implementation worth looking at 👀
ataractic
ataractic•11mo ago
sure!
More Posts
Simple Deno program on Windows quits after 20 secondsHi I have created a simple deno program and now compiled to an exe file for window using the commanNeed some help for Deno/FreshJS projectI have a Deno/FreshJS project and need some help from someone with extensive experience in Deno/FresI need more help understanding imports and relative paths for a module I am writingI am diving into the world of Deno and I am trying to port an existing node CLI. _If you are develIs there an idiomatic/common/modern way of creating a queue of jobs to be executed one after anot...Is there an idiomatic/common/modern way of creating a queue of jobs to be executed one after anotherLaunch tests with unstable flag inside VS CodeHi there, I'm creating a module that uses FFI and Deno.dlopen and I wrote tests to validate some of What is the difference between JS Map and JS Object?I know that `Map` is hash table implementation for JS, but how does it differ from an object? With rDeno KV: Should I expect 'value too large' errors inserting a JSON file with kv.set?I was trying out kv and quickly ran into something I found surprising; ```js let kv = await Deno.oDeno language server stops working in VS CodeAfter some random time the language server stops working and I suddenly get code errors like this: `Getting free disk space without using child_process.Hello everyone! I would like to create a small CLI tool using Typescript and Deno. I would like to mtest --filter a stepCan I only run a certain step in the test?