diff --git a/package-lock.json b/package-lock.json index bb9f27e..5bc9387 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@hibas123/utils", - "version": "2.1.0", + "version": "2.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 115ff29..a815faf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/utils", - "version": "2.2.1", + "version": "2.2.3", "description": "Different Utilities, that are not worth own packages", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/awaiter.ts b/src/awaiter.ts index 150f413..a86c02c 100644 --- a/src/awaiter.ts +++ b/src/awaiter.ts @@ -18,8 +18,7 @@ export default class AwaitStore { subscribe(handler: ObserverCallback) { handler(this._value); - this.observable.subscribe(handler); - return () => this.unsubscribe(handler); + return this.observable.subscribe(handler); } unsubscribe(handler: ObserverCallback) { @@ -34,23 +33,11 @@ export default class AwaitStore { const cb = () => { if (this._value === val) { yes(); - this.observable.unsubscribe(cb); - return true; - } - - return false - } - - if (this._value === val) { - yes(); - } else { - ignore = () => { - this.observable.unsubscribe(cb); - } - if (!cb()) { - this.observable.subscribe(cb); + this.unsubscribe(cb); } } + + this.subscribe(cb); }); return { diff --git a/src/observable.ts b/src/observable.ts index 5770394..b9835a4 100755 --- a/src/observable.ts +++ b/src/observable.ts @@ -92,7 +92,15 @@ export default class Observable { send(data: T) { if (this[ClosedSymbol]) throw new Error("Observable is closed!") - this.subscriber.forEach(e => e(data)); + + Array.from(this.subscriber.values()).forEach(e => { + try { + e(data) + } catch (err) { + // Catch error, so it doesn't affect other subscribers + console.error(err) + } + }); this.events.push(data); if (!this.timeout) { this.timeout = setTimeout(() => {