D
Deno

help

How do I enqueue_microtask from other thread

EExidex7/2/2023
so Isolate.enqueue_microtask is obviously not send/sync so I think the only option is to use std::sync::mpsc::channel and use Receiver.try_recv to get the values from Sender on other thread. The problem is that I am being a rust newbie don't know how to combine them on the single thread or if it actually possible. I somehow need to wake up the runtime when the Sender actually sends the value, I think I can wrap try_recv with poll_fn and use something like tokio's select! macro but that also doesn't seem to fit my problem because I need to be able to restart run_event_loop to process any new microtasks. Any pointers?
ABTAndreu Botella (they/them)7/2/2023
the easiest way is probably to have an op that listens for mpsc messages the op would resolve when the message arrives, and return the passed value to JS and then on an extension script, you would call that op on an async loop
(async () => {
while (true) {
const value = await Deno.core.opAsync("op_mspc_recv");
process(value);
}
})();
(async () => {
while (true) {
const value = await Deno.core.opAsync("op_mspc_recv");
process(value);
}
})();
EExidex7/2/2023
cool, that looks like it could actually work. thanks for the help
ABTAndreu Botella (they/them)7/2/2023
that loop would keep the event loop alive if you don't want that, you can do
const promise = Deno.core.opAsync("op_mspc_revc");
Deno.core.unrefOp(promise[Symbol.for("Deno.core.internalPromiseId")]);
const value = await promise;
const promise = Deno.core.opAsync("op_mspc_revc");
Deno.core.unrefOp(promise[Symbol.for("Deno.core.internalPromiseId")]);
const value = await promise;
similar to how Deno.unrefTimer works
EExidex7/2/2023
how is it better/worse? oh it doesn't block the event loop from stopping
ABTAndreu Botella (they/them)7/2/2023
right

Looking for more? Join the community!

Recommended Posts
how to import svg in vite without type errors?Can't connect to http server on official alpine deno with std serve.I'm using the official alpine docker container to run deno, listening on port 8080, but a simple curcalling a javascript function and waiting for the promise with `rusty_v8````rust let result = function.call(scope, recv, &[]).expect("couldnt run"); /*i got this result whicDeno KV: subtract with `sum` operation?If I do `.sum([key], 1n)` the value is increased by 1. How can I decrease it? I tried `.sum([key], How to use declarations from `vite/client`?There are declarations: https://esm.sh/v126/vite@4.3.9/client.d.ts According to documentation, I neegetting errno with ffiI am using ffi to call `execv` and need to get the value of `errno` for failures, but can’t see how Purging Kv keysI have a logger which write logs to a kv store with dual keys, something like ```ts kv.set(["logs_bWhat is the right way to bundle native modules?If I'm not able to import a native module with the built-in "import" keyword, what is the ideal way HandleScope in async opIs there a way to get v8::HandleScope inside async op if I add it as ``` scope: &mut v8::HandleScopDeno LSP randomly breaks until a restart (unable to send result to client)This wasnt an issue until recently. In vscode randomly the lsp stops working. Trying to use the autoIs anyone working on LLMs for Deno so I don't have to learn it in disgusting Python?I'm coming to terms with the reality of having to learn this technology but not on Python.. I mean..Permission denied (os error 13)Please help me, I'm desparate. It doesn't print anything else.Is there a rich text (wysiwyg) editor for deno fresh ?I'm working on a blog, and i need a rich text editor for articles.deno_core usageAre there any repos using deno_core in their code + how would I enable the unstable features and URLError reading `allocUnsafe` using npm:icsHello there, I try to use npm:ics in my project and in some runs it works, in others it doesn't (whiUsing discord.js in Deno?Apparently Deno supports discord.js now. Awesome. But now I can't make it work. According to debug Type alias with inherited type parameter constraintsIs there any way to do this? I want SVLTN to just be a short-name alias for SomeVeryLongTypeName, anFresh: global stateIs it possible to have a global state that can be accessed from anywhere? Currently I'm passing the Run Deno on Linux without /proc mountedI have a few automatic scripts using deno to run stuff, and wanted to migrate them to another MachinReasons to choose Node.jsI've been tasked to write a list of pros/cons of Deno in comparison to Node.js. I am quite honestly