Skip to content

Add support for the new using keyword#500

Merged
peter-leonov-ch merged 10 commits intomainfrom
disposable-api-support
Dec 17, 2025
Merged

Add support for the new using keyword#500
peter-leonov-ch merged 10 commits intomainfrom
disposable-api-support

Conversation

@peter-leonov-ch
Copy link
Copy Markdown
Collaborator

@peter-leonov-ch peter-leonov-ch commented Dec 16, 2025

Summary

Implements #492

It allows for tricks like:

async function getResults(client) {
  await using rs = client.query()
  throw new Error()
  // rs gets disposed automatically here like if the whole function body
  // was wrapped in a try / finally block
}

What

  • implemented the dispose methods
  • added a few utility functions (not DRY to avoid cross package unit test dependencies for now)

For the future:

  • try setting the test setup so that packages could reuse some basic helper functions like sleep()
  • try running tests conditionally per runner version (like Node.js 24, Chrome, etc)

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@peter-leonov-ch peter-leonov-ch changed the title Support for the new using keyword Support for the new using keyword Dec 16, 2025
@peter-leonov-ch peter-leonov-ch changed the title Support for the new using keyword Add support for the new using keyword Dec 16, 2025
@peter-leonov-ch peter-leonov-ch marked this pull request as ready for review December 16, 2025 20:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for JavaScript's explicit resource management (using keyword) by adding Symbol.dispose and Symbol.asyncDispose methods to the client and result set classes. This enables automatic cleanup when these resources are used with the using and await using statements.

Key Changes:

  • Added disposal methods to ClickHouseClient, ResultSet (web), and ResultSet (node) classes
  • Created feature detection utilities and test helpers for the using statement
  • Added comprehensive unit tests for the new disposal functionality

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/client-web/src/result_set.ts Added Symbol.asyncDispose method to web ResultSet for async disposal
packages/client-node/src/result_set.ts Added Symbol.dispose method to Node.js ResultSet for sync disposal
packages/client-common/src/client.ts Added Symbol.asyncDispose method to ClickHouseClient for async disposal
packages/client-web/tests/utils/sleep.ts Added sleep utility function for async test delays
packages/client-web/tests/utils/feature_detection.ts Added feature detection for using statement support
packages/client-web/tests/unit/web_result_set.test.ts Added test for ResultSet disposal with await using statement
packages/client-web/tests/unit/web_client.test.ts Added test for client disposal with await using statement
packages/client-node/tests/utils/sleep.ts Added sleep utility function for async test delays
packages/client-node/tests/utils/feture_detection.ts Added feature detection for using statement support
packages/client-node/tests/unit/node_result_set.test.ts Added test for ResultSet disposal with using statement
packages/client-node/tests/unit/node_client.test.ts Added test for client disposal with await using statement
packages/client-common/tests/unit/client.test.ts Added test for common client disposal with await using statement
CHANGELOG.md Documented the new Disposable API support feature
Comments suppressed due to low confidence (1)

packages/client-node/tests/utils/feture_detection.ts:1

  • Corrected spelling of 'feture' to 'feature' in filename.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@peter-leonov-ch peter-leonov-ch merged commit d056b49 into main Dec 17, 2025
27 checks passed
@peter-leonov-ch peter-leonov-ch deleted the disposable-api-support branch December 17, 2025 14:50
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

Successfully merging this pull request may close these issues.

3 participants