Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cancellation #69

Open
tschuchortdev opened this issue Feb 24, 2025 · 0 comments
Open

Support cancellation #69

tschuchortdev opened this issue Feb 24, 2025 · 0 comments

Comments

@tschuchortdev
Copy link

tschuchortdev commented Feb 24, 2025

Currently it is not possible to cancel queries in scalasql. It would be nice to support this feature since cancellation is a big deal in Cats-Effect and generally useful for long running queries. The easiest way to support cancellation transparently would be through the InterruptableException mechanism. However, to cancel a running query, stmt.cancel() needs to be called on the JDBC Statement and this necessarily has to happen on another thread because the primary thread is blocked waiting for the stsmt.executeUpdate(). Starting threads inside scalasql is not very performant and probably against the design principles of this library, so I propose instead to add something like a def transactionCancellable[T](block: DbApi.Txn => T)(implicit ec: ExecutionContext): (Future[T], /*cancel*/ () => Unit) function to DbClient. This will allow users to control where the thread is started through ExecutionContext. The standard blocking def transaction could perhaps be implemented with ExecutionContext.parasitic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant