redis icon indicating copy to clipboard operation
redis copied to clipboard

Support AbortController in a client

Open nounder opened this issue 1 year ago • 1 comments

Currently it is not possible pass AbortController signal to a client. It would be immensely useful to support that in streaming HTTP handlers.

Example:

http.serve(async (req: Request) => {
  const redis = await connect({ hostname: "127.0.0.1", signal: req.signal })
  const events = new http.ServerSentEventStreamTarget({ keepAlive: true })

  while (true) {
    const [stream] = await redis.xread([
      { key: `worker:${id}:events`, xid: "*" },
    ])

    // Send events from a stream.
  }

  return events.asResponse()
})

nounder avatar May 21 '23 12:05 nounder

Current solution:

const redis = await connect({
  hostname: "127.0.0.1",
})

req.signal.addEventListener("abort", () => {
  redis.close()
})

nounder avatar May 21 '23 12:05 nounder