Skip to content

Commit

Permalink
Remove deprecated overloads for DisposableStack/AsyncDisposableStack.…
Browse files Browse the repository at this point in the history
…p.use
  • Loading branch information
rbuckton committed Jul 9, 2023
1 parent a897c9f commit 7973b87
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 83 deletions.
28 changes: 3 additions & 25 deletions packages/disposable/src/__tests__/asyncDisposableStack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,7 @@ describe("Properties of the AsyncDisposableStack prototype [spec]", () => {
await stack.disposeAsync();
expect(steps).toEqual(["step 2", "step 1"]);
});
it("(deprecated) treats non-disposable function as disposable", async () => {
const fn = jest.fn<() => Promise<void>>().mockResolvedValue();
const stack = new AsyncDisposableStack();
stack.use(fn);
await stack.disposeAsync();
expect(fn).toHaveBeenCalled();
});
it("(deprecated) pass custom dispose for resource", async () => {
const fn = jest.fn<() => Promise<void>>().mockResolvedValue();
const resource = {};
const stack = new AsyncDisposableStack();
const result = stack.use(resource, fn);
await stack.disposeAsync();
expect(result).toBe(resource);
expect(fn).toHaveBeenCalled();
});
it("(deprecated) custom dispose invoked even if resource is null/undefined", async () => {
const fn = jest.fn<() => Promise<void>>().mockResolvedValue();
const stack = new AsyncDisposableStack();
stack.use(null, fn);
await stack.disposeAsync();
expect(fn).toHaveBeenCalled();
});
it("throws if wrong target", () => expect(() => AsyncDisposableStack.prototype.use.call({}, undefined!, undefined!)).toThrow());
it("throws if wrong target", () => expect(() => AsyncDisposableStack.prototype.use.call({}, undefined!)).toThrow());
it("throws if called after disposed", async () => {
const stack = new AsyncDisposableStack();
await stack.disposeAsync();
Expand Down Expand Up @@ -195,7 +172,8 @@ describe("Properties of the AsyncDisposableStack prototype [spec]", () => {
});
it("resources from initial stack disposed after new stack from move is disposed", async () => {
const stack = new AsyncDisposableStack();
const fn = stack.use(jest.fn<() => void>());
const fn = jest.fn<() => void>()
stack.defer(fn);
const newStack = stack.move();
await newStack[AsyncDisposable.asyncDispose]();
expect(fn).toHaveBeenCalled();
Expand Down
25 changes: 1 addition & 24 deletions packages/disposable/src/__tests__/disposableStack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,7 @@ describe("Properties of the DisposableStack prototype [spec]", () => {
stack.dispose();
expect(steps).toEqual(["step 2", "step 1"]);
});
it("(deprecated) treats non-disposable function as disposable", () => {
const fn = jest.fn();
const stack = new DisposableStack();
stack.use(fn);
stack.dispose();
expect(fn).toHaveBeenCalled();
});
it("(deprecated) pass custom dispose for resource", () => {
const fn = jest.fn();
const resource = {};
const stack = new DisposableStack();
const result = stack.use(resource, fn);
stack.dispose();
expect(result).toBe(resource);
expect(fn).toHaveBeenCalled();
});
it("custom dispose invoked even if resource is null/undefined", () => {
const fn = jest.fn();
const stack = new DisposableStack();
stack.use(null, fn);
stack.dispose();
expect(fn).toHaveBeenCalled();
});
it("throws if wrong target", () => expect(() => DisposableStack.prototype.use.call({}, undefined!, undefined!)).toThrow());
it("throws if wrong target", () => expect(() => DisposableStack.prototype.use.call({}, undefined!)).toThrow());
it("throws if called after disposed", () => {
const stack = new DisposableStack();
stack.dispose();
Expand Down
18 changes: 1 addition & 17 deletions packages/disposable/src/asyncDisposableStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ export class AsyncDisposableStack implements AsyncDisposable {
* @param value The resource to add.
* @returns The resource provided.
*/
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T;
/** @deprecated Use {@link defer|defer()} instead. */
use<T extends () => void | PromiseLike<void>>(value: T): T;
/** @deprecated Use {@link adopt|adopt()} instead. */
use<T>(value: T, onDisposeAsync: (value: T) => void | PromiseLike<void>): T;
use<T>(value: T, onDisposeAsync: ((value: T) => void | PromiseLike<void>) | undefined = undefined): T {
use<T extends AsyncDisposable | Disposable | null | undefined>(value: T): T {
// 11.4.3.3 AsyncDisposableStack.prototype.use( _value_ )

// 1. Let _asyncDisposableStack_ be the *this* value.
Expand All @@ -124,17 +119,6 @@ export class AsyncDisposableStack implements AsyncDisposable {
// 3. If _asyncDisposableStack_.[[AsyncDisposableState]] is ~disposed~, throw a *ReferenceError* exception.
if (disposableState === "disposed") throw new ReferenceError("Object is disposed");

// NOTE: 1.0.0 compatibility:
if (onDisposeAsync !== undefined) {
return this.adopt(value, onDisposeAsync);
}

// NOTE: 1.0.0 compatibility:
if (value !== null && value !== undefined && typeof value === "function" && !(AsyncDisposable.asyncDispose in value) && !(Disposable.dispose in value)) {
this.defer(value as unknown as DisposeMethod<"async-dispose">);
return value;
}

// 4. Perform ? AddDisposableResource(_asyncDisposableStack_.[[DisposeCapability]], _value_, ~async-dispose~).
AddDisposableResource(weakDisposeCapability.get(this)!, value, "async-dispose");

Expand Down
18 changes: 1 addition & 17 deletions packages/disposable/src/disposableStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ export class DisposableStack {
* @param value The resource to add.
* @returns The resource provided.
*/
use<T extends Disposable | null | undefined>(value: T): T;
/** @deprecated Use {@link defer|defer()} instead. */
use<T extends () => void>(value: T): T;
/** @deprecated Use {@link adopt|adopt()} instead. */
use<T>(value: T, onDispose: (value: T) => void): T;
use<T>(value: T, onDispose: ((value: T) => void) | undefined = undefined): T {
use<T extends Disposable | null | undefined>(value: T): T {
// 11.3.3.3 DisposableStack.prototype.use ( _value_ )

// 1. Let _disposableStack_ be the *this* value.
Expand All @@ -119,17 +114,6 @@ export class DisposableStack {
// 3. If _disposableStack_.[[DisposableState]] is ~disposed~, throw a *ReferenceError* exception.
if (disposableState === "disposed") throw new ReferenceError("Object is disposed");

// NOTE: 1.0.0 compatibility:
if (onDispose !== undefined) {
return this.adopt(value, onDispose);
}

// NOTE: 1.0.0 compatibility:
if (value !== null && value !== undefined && typeof value === "function" && !(Disposable.dispose in value)) {
this.defer(value as unknown as DisposeMethod<"sync-dispose">);
return value;
}

// 4. Perform ? AddDisposableResource(_disposableStack_.[[DisposeCapability]], _value_, ~sync-dispose~).
AddDisposableResource(weakDisposeCapability.get(this)!, value, "sync-dispose");

Expand Down

0 comments on commit 7973b87

Please sign in to comment.