JacobZwang
JacobZwang
DDeno
Created by JacobZwang on 7/29/2024 in #help
use `process` without importing it
Is there a way to enable the global process variable without manually importing it from node:process? This would help a lot with making node projects compatible with deno without any code change.
4 replies
DDeno
Created by JacobZwang on 6/28/2024 in #help
node stream.Readable.on not a function.
In Node we can listen to data on a readable stream using .on("data"). This method does not seem to exist in Deno. What should we use as a replacement and is it compatible with node?
2 replies
DDeno
Created by JacobZwang on 5/22/2024 in #help
How to import enums from npm:typescript package?
The following code crashes because the enum is undefined at runtime.
import * as ts from "npm:typescript";
console.log(ts.ScriptTarget.ESNext);
import * as ts from "npm:typescript";
console.log(ts.ScriptTarget.ESNext);
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'ESNext')
target: ts.ScriptTarget.ESNext,
error: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'ESNext')
target: ts.ScriptTarget.ESNext,
I think this issue is related, but I can't figure out how to actually solve this. https://github.com/denoland/deno/issues/7605 I tried running it in Bun and it worked as expected and I can't find any compiler options in deno that seem related. How should I fix this?
6 replies
DDeno
Created by JacobZwang on 4/26/2024 in #help
block js with #[op2] fn without blocking rust thread
I'm using deno_core and I'm looking for a way to block the js main thread without using a sync function to block rust's thread.
#[op2(async)]
#[string]
async fn op_sleep() -> Result<(), AnyError> { // should not block rust thread
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
Ok(())
}
#[op2(async)]
#[string]
async fn op_sleep() -> Result<(), AnyError> { // should not block rust thread
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
Ok(())
}
Deno.core.ops.op_sleep() // should block js runtime for 1 second
Deno.core.ops.op_sleep() // should block js runtime for 1 second
Basically what should happen is: 1. op_sleep is called from js. 2. rust pauses the js runtime for 1 second. during this 1 second, rust thread is can still be executing other isolates on the same thread. 3. after 1 second ends, rust resumes the js runtime. Is this possible using deno_core and op2 or do I need to use lower level apis?
2 replies