kingbriK
Denoβ€’14mo agoβ€’
1 reply
kingbri

AbortSignals not working in Deno

Hi there,
I'm trying to create a Hono server with a disconnect handler. When I cancel the request from my client, the abort signal from the raw Request object never changes to true. This code works on both Hono and Bun, so I think this is an issue with Deno's fetch API. See example below (requires Hono)

import { Hono } from 'hono'

const app = new Hono()

async function stall(stallTime = 3000) {
  await new Promise(resolve => setTimeout(resolve, stallTime));
}

app.get('/hello', async (c) => {

  // Should show up when hitting Cancel in Postman
  c.req.raw.signal.addEventListener("abort", () => {
    console.log("Aborted");
  })

  // Simulate a long-running task
  await stall(10000);
  return c.text("Hello from Hono!");
})

Deno.serve(app.fetch)
Was this page helpful?