@wixc3/patterns
Advanced tools
Comparing version 15.3.0 to 15.3.1
@@ -41,3 +41,3 @@ import { Disposables } from '.'; | ||
private _isDisposed; | ||
private _isDisposing; | ||
private _isDisposing?; | ||
private timeouts; | ||
@@ -44,0 +44,0 @@ private intervals; |
@@ -44,3 +44,2 @@ "use strict"; | ||
this._isDisposed = false; | ||
this._isDisposing = false; | ||
this.timeouts = new Set(); | ||
@@ -51,3 +50,3 @@ this.intervals = new Set(); | ||
*/ | ||
this.isDisposed = () => this._isDisposed || this._isDisposing; | ||
this.isDisposed = () => !!(this._isDisposed || this._isDisposing); | ||
this.registerGroup(DELAY_DISPOSAL, { before: 'default' }); | ||
@@ -73,7 +72,10 @@ this.add('dispose timeouts and intervals', () => { | ||
async dispose() { | ||
if (!this.isDisposed() && !this._isDisposing) { | ||
this._isDisposing = true; | ||
await super.dispose(); | ||
if (this.isDisposed()) { | ||
return this._isDisposing; | ||
} | ||
else { | ||
this._isDisposing = super.dispose(); | ||
await this._isDisposing; | ||
this._isDisposed = true; | ||
this._isDisposing = false; | ||
this._isDisposing = undefined; | ||
} | ||
@@ -85,3 +87,3 @@ } | ||
const { fn, options: { name, timeout, usedWhileDisposing }, } = extractArgs(fnOrOptions, options); | ||
if (this.isDisposed() && !(this._isDisposing && usedWhileDisposing)) { | ||
if (this.isDisposed() && !(usedWhileDisposing && this._isDisposing)) { | ||
throw new Error('Instance was disposed'); | ||
@@ -88,0 +90,0 @@ } |
@@ -41,3 +41,3 @@ import { Disposables } from '.'; | ||
private _isDisposed; | ||
private _isDisposing; | ||
private _isDisposing?; | ||
private timeouts; | ||
@@ -44,0 +44,0 @@ private intervals; |
@@ -41,3 +41,2 @@ import { Disposables } from '.'; | ||
this._isDisposed = false; | ||
this._isDisposing = false; | ||
this.timeouts = new Set(); | ||
@@ -48,3 +47,3 @@ this.intervals = new Set(); | ||
*/ | ||
this.isDisposed = () => this._isDisposed || this._isDisposing; | ||
this.isDisposed = () => !!(this._isDisposed || this._isDisposing); | ||
this.registerGroup(DELAY_DISPOSAL, { before: 'default' }); | ||
@@ -70,7 +69,10 @@ this.add('dispose timeouts and intervals', () => { | ||
async dispose() { | ||
if (!this.isDisposed() && !this._isDisposing) { | ||
this._isDisposing = true; | ||
await super.dispose(); | ||
if (this.isDisposed()) { | ||
return this._isDisposing; | ||
} | ||
else { | ||
this._isDisposing = super.dispose(); | ||
await this._isDisposing; | ||
this._isDisposed = true; | ||
this._isDisposing = false; | ||
this._isDisposing = undefined; | ||
} | ||
@@ -82,3 +84,3 @@ } | ||
const { fn, options: { name, timeout, usedWhileDisposing }, } = extractArgs(fnOrOptions, options); | ||
if (this.isDisposed() && !(this._isDisposing && usedWhileDisposing)) { | ||
if (this.isDisposed() && !(usedWhileDisposing && this._isDisposing)) { | ||
throw new Error('Instance was disposed'); | ||
@@ -85,0 +87,0 @@ } |
{ | ||
"name": "@wixc3/patterns", | ||
"version": "15.3.0", | ||
"version": "15.3.1", | ||
"description": "A utility for saving objects to be disposed", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js", |
@@ -47,3 +47,3 @@ import { Disposables } from '.'; | ||
private _isDisposed = false; | ||
private _isDisposing = false; | ||
private _isDisposing?: Promise<void>; | ||
private timeouts = new Set<ReturnType<typeof setTimeout>>(); | ||
@@ -74,7 +74,9 @@ private intervals = new Set<ReturnType<typeof setInterval>>(); | ||
override async dispose() { | ||
if (!this.isDisposed() && !this._isDisposing) { | ||
this._isDisposing = true; | ||
await super.dispose(); | ||
if (this.isDisposed()) { | ||
return this._isDisposing; | ||
} else { | ||
this._isDisposing = super.dispose(); | ||
await this._isDisposing; | ||
this._isDisposed = true; | ||
this._isDisposing = false; | ||
this._isDisposing = undefined; | ||
} | ||
@@ -86,3 +88,3 @@ } | ||
*/ | ||
isDisposed = () => this._isDisposed || this._isDisposing; | ||
isDisposed = () => !!(this._isDisposed || this._isDisposing); | ||
@@ -121,3 +123,3 @@ /** | ||
if (this.isDisposed() && !(this._isDisposing && usedWhileDisposing)) { | ||
if (this.isDisposed() && !(usedWhileDisposing && this._isDisposing)) { | ||
throw new Error('Instance was disposed'); | ||
@@ -124,0 +126,0 @@ } |
@@ -22,2 +22,14 @@ import { expect } from 'chai'; | ||
}); | ||
describe('when called multiple times', () => { | ||
it('returns a promise that resolves when all disposals are done', async () => { | ||
const resolved: string[] = []; | ||
const disposable = new SafeDisposable('test'); | ||
disposable.add('sleep', () => sleep(20)); | ||
void disposable.dispose().then(() => resolved.push('initial')); | ||
await disposable.dispose().then(() => resolved.push('before completion')); | ||
expect(resolved).to.eql(['initial', 'before completion']); | ||
await disposable.dispose().then(() => resolved.push('after completion')); | ||
expect(resolved).to.eql(['initial', 'before completion', 'after completion']); | ||
}); | ||
}); | ||
}); | ||
@@ -24,0 +36,0 @@ describe('guard', () => { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
261875
5066