Unblock subsequent Singleton.createInstance() (#3225)

- Also fix clusters with unknown workspaces

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2021-07-06 17:16:04 +03:00
1 parent c4623c424d
commit 803c3a3d34
3 files changed
+15 -5

No files matched your search

+7 -4
View File
@@ -46,12 +46,15 @@ export class Singleton {
static createInstance<T, R extends any[]>(this: StaticThis<T, R>, ...args: R): T {
if (!Singleton.instances.has(this)) {
if (Singleton.creating.length > 0) {
throw new TypeError("Cannot create a second singleton while creating a first");
throw new TypeError(`Cannot create a second singleton (${this.name}) while creating a first (${Singleton.creating})`);
}
Singleton.creating = this.name;
Singleton.instances.set(this, new this(...args));
Singleton.creating = "";
try {
Singleton.creating = this.name;
Singleton.instances.set(this, new this(...args));
} finally {
Singleton.creating = "";
}
}
return Singleton.instances.get(this) as T;