Writing Static Classes
type Config = {
instances: number;
};
class Task {
static #nextId = 0;
static #maxInstances: number;
#id: number;
static {
fetch("/available-slots")
.then((res) => res.json())
.then((result: Config) => {
Task.#maxInstances = result.instances;
});
}
constructor() {
if (Task.#nextId > Task.#maxInstances) {
throw "Max number of tasks reached";
}
this.#id = Task.#nextId++;
}
}