Exidex
Exidex14mo ago

Async OP that returns value instead of promise

In deno_runtime is possible to have async op that returns the resolved value instead of promise? Kinda like calling tokio's block_on in the op (is it possible)? For my use case i use crate in that uses async but in js I use library that will call this op but it doesn't support async. I there any way to work around this problem?
6 Replies
AapoAlas
AapoAlas14mo ago
That would be a blocking / sync op then
Exidex
Exidex14mo ago
I think It depends, if deno has support for something like this it could be async op that deno itself would block on and resolve OR it will be sync op which I would block on inside the op. The problem is I don't know how to get a tokio's runtime into the op with all the ownership rules, or if it is even possible given that the whole deno execution is inside a block_on
AapoAlas
AapoAlas14mo ago
From JavaScript's perspective it is necessarily a blocking operation since it returns a value. Unfortunately I don't really know about the tokio event loop binding for deno_runtime though.
Andreu Botella (they/them)
I implemented something like that for testing classic workers on WPT I don't remember how I did it though
Andreu Botella (they/them)
GitHub
deno/sync_fetch.rs at main · denoland/deno
A modern runtime for JavaScript and TypeScript. Contribute to denoland/deno development by creating an account on GitHub.
Exidex
Exidex14mo ago
creating new thread and a runtime seems excessive to be done on each op call