Comment by ncruces

Comment by ncruces a day ago

0 replies

It's well scoped, but not short lived; it's an SQLite connection.

But the API surface is huge, with 100s of methods on the connection and derived objects, with it being unclear which might block and be worthy of asynchronous cancellation. You never know when pulling an additional column if that one might be an overflow text/blob that does additional IO.

The solution, while not amazing is a method that you use like this:

  old := conn.SetInterrupt(ctx)
  defer conn.SetInterrupt(old)
This changes the “interrupt” context for the duration of your function scope, and covers all potentially blocking calls that you might make. Also, from the name, it's quite clear that this context is used only for interruption/cancellation (interrupt is the SQLite name for this, which I try to adhere to).