diff --git a/jest.config.js b/jest.config.js index 1eaaa78..4c08e8f 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,14 +1,19 @@ module.exports = { - preset: 'ts-jest', + preset: 'ts-jest/presets/js-with-ts', roots: ['src'], transformIgnorePatterns: ['/node_modules/.*\\.js', '/build/.*\\.js'], + transform: { + '^.+\\.tsx?$': [ + 'ts-jest', + { + tsconfig: { + target: 'es2022', + }, + }, + ], + }, testMatch: ['**/__test__/*\\.(ts|js|tsx|jsx)', '**/*\\.(spec|test)\\.(ts|js|tsx|jsx)'], collectCoverageFrom: ['src/**/*.(ts|tsx)', '!build/', '!**/node_modules', '!/coverage'], moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], coverageReporters: ['json', 'lcov', 'text', 'html'], - globals: { - 'ts-jest': { - isolatedModules: true, - }, - }, }; diff --git a/src/concurrency/locks/lockable.spec.ts b/src/concurrency/locks/lockable.spec.ts index 99a0e25..9739d84 100644 --- a/src/concurrency/locks/lockable.spec.ts +++ b/src/concurrency/locks/lockable.spec.ts @@ -1,3 +1,3 @@ describe('ResourcePool lock', () => { - it.skip(''); + it.todo(''); }); diff --git a/src/concurrency/resource-pool.ts b/src/concurrency/resource-pool.ts index e795cfc..acf820c 100644 --- a/src/concurrency/resource-pool.ts +++ b/src/concurrency/resource-pool.ts @@ -40,8 +40,12 @@ export class ResourcePool { } async use(task: (res: T) => R): Promise> { - await using lease = await this.borrow(); - return await task(lease.value); + const lease = await this.borrow(); + try { + return await task(lease.value); + } finally { + await lease[Symbol.asyncDispose](); + } } tryUse(task: (res: T | null) => R): R | Promise> { @@ -88,13 +92,16 @@ export class ResourcePool { async borrow(timeout?: number): Promise> { const v = await this._borrow(); + // console.log('borrowed', v); + const _return = lazyThenable(async () => { this._return(v); + // console.log('returned', v); }); return { value: v, - async [Symbol.asyncDispose]() { + [Symbol.asyncDispose]: async () => { await _return; }, }; diff --git a/tsconfig.json b/tsconfig.json index f6bc429..0eb3c8e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "jsx": "preserve", "module": "commonjs", "moduleResolution": "node", - "target": "es2021", + "target": "es2022", "skipLibCheck": true, "rootDir": "src", "outDir": "lib"