Socket
Socket
Sign inDemoInstall

@wixc3/patterns

Package Overview
Dependencies
Maintainers
66
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wixc3/patterns - npm Package Compare versions

Comparing version 15.1.1 to 15.2.0

dist/cjs/disposables/types.d.ts

1

dist/cjs/disposables/index.d.ts
export * from './create-disposables';
export * from './disposable';
export * from './safe-disposable';
export * from './types';
export type { DisposableItem } from './disposables-group';
export { DisposalGroup, GroupConstraints } from './constraints';
//# sourceMappingURL=index.d.ts.map

@@ -20,2 +20,3 @@ "use strict";

__exportStar(require("./safe-disposable"), exports);
__exportStar(require("./types"), exports);
//# sourceMappingURL=index.js.map

6

dist/cjs/disposables/safe-disposable.d.ts
import { Disposables } from '.';
export type IDisposable = {
dispose: () => unknown;
};
import { IDisposable } from './types';
declare const DISPOSAL_GUARD_DEFAULTS: {

@@ -64,3 +62,3 @@ name: string;

*/
get isDisposed(): boolean;
isDisposed: () => boolean;
/**

@@ -67,0 +65,0 @@ * After disposal starts, it's necessary to avoid executing some code. `guard` is used for those cases.

@@ -6,3 +6,3 @@ "use strict";

const promise_assist_1 = require("promise-assist");
const DELAY_DISPOSAL = 'unreleased disposal guard - did you forget to use "using _ = this.guard()"?';
const DELAY_DISPOSAL = 'unreleased disposal guard, an async guarded task is still running';
const DISPOSAL_GUARD_DEFAULTS = {

@@ -48,2 +48,6 @@ name: 'unsafe execution: instance was disposed',

this.intervals = new Set();
/**
* returns true if the disposal process started
*/
this.isDisposed = () => this._isDisposed || this._isDisposing;
this.registerGroup(DELAY_DISPOSAL, { before: 'default' });

@@ -69,3 +73,3 @@ this.add('dispose timeouts and intervals', () => {

async dispose() {
if (!this.isDisposed && !this._isDisposing) {
if (!this.isDisposed() && !this._isDisposing) {
this._isDisposing = true;

@@ -77,8 +81,2 @@ await super.dispose();

}
/**
* returns true if the disposal process started
*/
get isDisposed() {
return this._isDisposed || this._isDisposing;
}
// guard<T>(options?: OPTIONS): { [Symbol.dispose]: () => void };

@@ -88,3 +86,3 @@ // @internal

const { fn, options: { name, timeout, usedWhileDisposing }, } = extractArgs(fnOrOptions, options);
if (this.isDisposed && !(this._isDisposing && usedWhileDisposing)) {
if (this.isDisposed() && !(this._isDisposing && usedWhileDisposing)) {
throw new Error('Instance was disposed');

@@ -112,12 +110,11 @@ }

setTimeout(fn, timeout) {
return this.guard(() => {
const handle = setTimeout(() => {
this.timeouts.delete(handle);
if (!this.isDisposed) {
fn();
}
}, timeout);
this.timeouts.add(handle);
return handle;
});
this.guard();
const handle = setTimeout(() => {
this.timeouts.delete(handle);
if (!this.isDisposed()) {
fn();
}
}, timeout);
this.timeouts.add(handle);
return handle;
}

@@ -129,11 +126,10 @@ /**

setInterval(fn, interval) {
return this.guard(() => {
const handle = setInterval(() => {
if (!this.isDisposed) {
fn();
}
}, interval);
this.intervals.add(handle);
return handle;
});
this.guard();
const handle = setInterval(() => {
if (!this.isDisposed()) {
fn();
}
}, interval);
this.intervals.add(handle);
return handle;
}

@@ -140,0 +136,0 @@ }

export * from './create-disposables';
export * from './disposable';
export * from './safe-disposable';
export * from './types';
export type { DisposableItem } from './disposables-group';
export { DisposalGroup, GroupConstraints } from './constraints';
//# sourceMappingURL=index.d.ts.map
export * from './create-disposables';
export * from './disposable';
export * from './safe-disposable';
export * from './types';
//# sourceMappingURL=index.js.map
import { Disposables } from '.';
export type IDisposable = {
dispose: () => unknown;
};
import { IDisposable } from './types';
declare const DISPOSAL_GUARD_DEFAULTS: {

@@ -64,3 +62,3 @@ name: string;

*/
get isDisposed(): boolean;
isDisposed: () => boolean;
/**

@@ -67,0 +65,0 @@ * After disposal starts, it's necessary to avoid executing some code. `guard` is used for those cases.

import { Disposables } from '.';
import { deferred } from 'promise-assist';
const DELAY_DISPOSAL = 'unreleased disposal guard - did you forget to use "using _ = this.guard()"?';
const DELAY_DISPOSAL = 'unreleased disposal guard, an async guarded task is still running';
const DISPOSAL_GUARD_DEFAULTS = {

@@ -44,2 +44,6 @@ name: 'unsafe execution: instance was disposed',

this.intervals = new Set();
/**
* returns true if the disposal process started
*/
this.isDisposed = () => this._isDisposed || this._isDisposing;
this.registerGroup(DELAY_DISPOSAL, { before: 'default' });

@@ -65,3 +69,3 @@ this.add('dispose timeouts and intervals', () => {

async dispose() {
if (!this.isDisposed && !this._isDisposing) {
if (!this.isDisposed() && !this._isDisposing) {
this._isDisposing = true;

@@ -73,8 +77,2 @@ await super.dispose();

}
/**
* returns true if the disposal process started
*/
get isDisposed() {
return this._isDisposed || this._isDisposing;
}
// guard<T>(options?: OPTIONS): { [Symbol.dispose]: () => void };

@@ -84,3 +82,3 @@ // @internal

const { fn, options: { name, timeout, usedWhileDisposing }, } = extractArgs(fnOrOptions, options);
if (this.isDisposed && !(this._isDisposing && usedWhileDisposing)) {
if (this.isDisposed() && !(this._isDisposing && usedWhileDisposing)) {
throw new Error('Instance was disposed');

@@ -108,12 +106,11 @@ }

setTimeout(fn, timeout) {
return this.guard(() => {
const handle = setTimeout(() => {
this.timeouts.delete(handle);
if (!this.isDisposed) {
fn();
}
}, timeout);
this.timeouts.add(handle);
return handle;
});
this.guard();
const handle = setTimeout(() => {
this.timeouts.delete(handle);
if (!this.isDisposed()) {
fn();
}
}, timeout);
this.timeouts.add(handle);
return handle;
}

@@ -125,11 +122,10 @@ /**

setInterval(fn, interval) {
return this.guard(() => {
const handle = setInterval(() => {
if (!this.isDisposed) {
fn();
}
}, interval);
this.intervals.add(handle);
return handle;
});
this.guard();
const handle = setInterval(() => {
if (!this.isDisposed()) {
fn();
}
}, interval);
this.intervals.add(handle);
return handle;
}

@@ -136,0 +132,0 @@ }

{
"name": "@wixc3/patterns",
"version": "15.1.1",
"version": "15.2.0",
"description": "A utility for saving objects to be disposed",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

export * from './create-disposables';
export * from './disposable';
export * from './safe-disposable';
export * from './types';
export type { DisposableItem } from './disposables-group';
export { DisposalGroup, GroupConstraints } from './constraints';
import { Disposables } from '.';
import { deferred } from 'promise-assist';
import { IDisposable } from './types';
export type IDisposable = {
dispose: () => unknown;
};
const DELAY_DISPOSAL = 'unreleased disposal guard - did you forget to use "using _ = this.guard()"?';
const DELAY_DISPOSAL = 'unreleased disposal guard, an async guarded task is still running';
const DISPOSAL_GUARD_DEFAULTS = {

@@ -76,3 +73,3 @@ name: 'unsafe execution: instance was disposed',

override async dispose() {
if (!this.isDisposed && !this._isDisposing) {
if (!this.isDisposed() && !this._isDisposing) {
this._isDisposing = true;

@@ -88,5 +85,3 @@ await super.dispose();

*/
get isDisposed(): boolean {
return this._isDisposed || this._isDisposing;
}
isDisposed = () => this._isDisposed || this._isDisposing;

@@ -125,3 +120,3 @@ /**

if (this.isDisposed && !(this._isDisposing && usedWhileDisposing)) {
if (this.isDisposed() && !(this._isDisposing && usedWhileDisposing)) {
throw new Error('Instance was disposed');

@@ -152,12 +147,11 @@ }

setTimeout(fn: () => void, timeout: number): ReturnType<typeof setTimeout> {
return this.guard(() => {
const handle = setTimeout(() => {
this.timeouts.delete(handle);
if (!this.isDisposed) {
fn();
}
}, timeout);
this.timeouts.add(handle);
return handle;
});
this.guard();
const handle = setTimeout(() => {
this.timeouts.delete(handle);
if (!this.isDisposed()) {
fn();
}
}, timeout);
this.timeouts.add(handle);
return handle;
}

@@ -170,11 +164,10 @@

setInterval(fn: () => void, interval: number): ReturnType<typeof setInterval> {
return this.guard(() => {
const handle = setInterval(() => {
if (!this.isDisposed) {
fn();
}
}, interval);
this.intervals.add(handle);
return handle;
});
this.guard();
const handle = setInterval(() => {
if (!this.isDisposed()) {
fn();
}
}, interval);
this.intervals.add(handle);
return handle;
}

@@ -181,0 +174,0 @@

@@ -9,5 +9,5 @@ import { expect } from 'chai';

const disposable = new SafeDisposable('test');
expect(disposable.isDisposed).to.be.false;
expect(disposable.isDisposed()).to.be.false;
await disposable.dispose();
expect(disposable.isDisposed).to.be.true;
expect(disposable.isDisposed()).to.be.true;
});

@@ -101,3 +101,3 @@ it('executes inner disposal functions', async () => {

disposable.guard(() => 'guarded return value'),
'guard return value',
'guard return value'
).to.eql('guarded return value');

@@ -122,3 +122,3 @@ const disposing = disposable.dispose();

expect(disposables.isDisposed, 'isDisposed').to.be.true;
expect(disposables.isDisposed(), 'isDisposed').to.be.true;
expect(disposeCalled, 'disposeCalled').to.be.false;

@@ -125,0 +125,0 @@ return 'guarded return value';

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc