CodyCC
Denoβ€’3y agoβ€’
3 replies
CodyC

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())
}


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"
}


Any suggestions? I guess I'll fire up a debugger...
Was this page helpful?