CodyC
CodyC
DDeno
Created by CodyC on 4/1/2024 in #help
How to open a file as blob?
Docs for Blob (https://deno.land/api@v1.42.0?s=Blob) say that File implements Blob. But the docs for Deno.File (https://deno.land/api@v1.42.0?s=Deno.File) say that it's deprecated and you should use FsFile instead. But FsFile (https://deno.land/api@v1.42.0?s=Deno.FsFile) doesn't implement Blob. I could probably write my own wrapper that will make FsFile conform to Blob, but that feels like something that might already be in std somewhere? (update: the important part here is that I want to wrap a file-like object, not read the entire file's contents into memory, since I'm working with potentially large files.)
20 replies
DDeno
Created by CodyC on 4/4/2023 in #help
Is there a way to lint check unnecessary `await`s?
1 replies
DDeno
Created by CodyC on 3/24/2023 in #help
Help debugging command that doesn't exit.
Is there a way to have Deno tell me what async tasks are still pending when a program ends? I'm using a third-party API, and AFAICT awaiting all the promises I can, but I still get to the end of my main() and deno doesn't exit. So I've got:
async function main() {
// [snip]
console.log("Done")
showPending()
}

function showPending() {
let {ops} = Deno.metrics()
for (let [key, value] of Object.entries(ops)) {
if (value.opsDispatched != value.opsCompleted) {
console.log(key, value)
}
}
console.log(Deno.resources())
}
async function main() {
// [snip]
console.log("Done")
showPending()
}

function showPending() {
let {ops} = Deno.metrics()
for (let [key, value] of Object.entries(ops)) {
if (value.opsDispatched != value.opsCompleted) {
console.log(key, value)
}
}
console.log(Deno.resources())
}
Which gives me:
[snip]
Done
op_read {
opsDispatched: 14,
opsDispatchedSync: 0,
opsDispatchedAsync: 14,
opsDispatchedAsyncUnref: 0,
opsCompleted: 13,
opsCompletedSync: 0,
opsCompletedAsync: 13,
opsCompletedAsyncUnref: 0,
bytesSentControl: 0,
bytesSentData: 0,
bytesReceived: 0
}
{
"0": "stdin",
"1": "stdout",
"2": "stderr",
"8": "childStdin",
"9": "childStdout",
"10": "child"
}
[snip]
Done
op_read {
opsDispatched: 14,
opsDispatchedSync: 0,
opsDispatchedAsync: 14,
opsDispatchedAsyncUnref: 0,
opsCompleted: 13,
opsCompletedSync: 0,
opsCompletedAsync: 13,
opsCompletedAsyncUnref: 0,
bytesSentControl: 0,
bytesSentData: 0,
bytesReceived: 0
}
{
"0": "stdin",
"1": "stdout",
"2": "stderr",
"8": "childStdin",
"9": "childStdout",
"10": "child"
}
Any suggestions? I guess I'll fire up a debugger...
4 replies
DDeno
Created by CodyC on 12/23/2022 in #help
Lint for if you forgot to `await` a Promise?
If you have async methods that you call for their side effects, it's easy to forget to await them. Is there a lint rule that I can enable for that? (Sort of like Rust's rules about unused Results?) ex:
async myFn() {
// code

// oops, I forgot to await:
doThing()

// more code
// fails at runtime because doThing()
// hasn't finished yet.

}
async myFn() {
// code

// oops, I forgot to await:
doThing()

// more code
// fails at runtime because doThing()
// hasn't finished yet.

}
6 replies