diff --git a/js/gulpfile.js b/js/gulpfile.js index b5d541a55d5..63da5404cd5 100644 --- a/js/gulpfile.js +++ b/js/gulpfile.js @@ -285,6 +285,12 @@ for (const name of tests) { let bundle = await rollup({ input: input, plugins: [IceResolver(), NodeMockupResolver()], + onwarn: (warning, next) => { + // Ignore the "this is undefined" warning, let rollup silently rewrite it. + // This avoids warnings from the TypeScript polyfills for async disposable resources. + if (warning.code === "THIS_IS_UNDEFINED") return; + next(warning); + }, }); await bundle.write({ file: path.join("dist", name, "index.js"), diff --git a/js/src/Ice/Communicator.d.ts b/js/src/Ice/Communicator.d.ts index cba9b22ed71..34232826cbe 100644 --- a/js/src/Ice/Communicator.d.ts +++ b/js/src/Ice/Communicator.d.ts @@ -22,6 +22,11 @@ declare module "ice" { */ destroy(): Promise; + /** + * Asynchronously disposes this communicator. It's an alias for {@link Communicator#destroy}. + */ + [Symbol.asyncDispose](): Promise; + /** * Shuts down this communicator. In JavaScript, shutdown resolves a promise and doesn't do anything else. * diff --git a/js/src/Ice/Communicator.js b/js/src/Ice/Communicator.js index 9c58da46438..e8620175aa6 100644 --- a/js/src/Ice/Communicator.js +++ b/js/src/Ice/Communicator.js @@ -21,6 +21,10 @@ export class Communicator { return this._instance.destroy(); } + [Symbol.asyncDispose]() { + return this.destroy(); + } + shutdown() { if (!this._isShutdown) { this._isShutdown = true; diff --git a/js/test/Ice/properties/Client.ts b/js/test/Ice/properties/Client.ts index 9590b79eb02..5a3bfaef760 100644 --- a/js/test/Ice/properties/Client.ts +++ b/js/test/Ice/properties/Client.ts @@ -118,7 +118,7 @@ export class Client extends TestHelper { } { - const communicator = Ice.initialize(args); + await using communicator = Ice.initialize(args); const properties = communicator.getProperties(); out.write("testing that creating an object adapter with unknown properties throws an exception...");