mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Prevent restarting a startableStoppable when already being started
Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com> Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
43598914ee
commit
34e504b65b
@ -57,6 +57,24 @@ describe("getStartableStoppable", () => {
|
||||
expect(actual.started).toBe(false);
|
||||
});
|
||||
|
||||
describe("when started again before the start has finished", () => {
|
||||
let error: Error;
|
||||
|
||||
beforeEach(() => {
|
||||
startMock.mockClear();
|
||||
|
||||
actual.start().catch((e) => { error = e; });
|
||||
});
|
||||
|
||||
it("does not start starting again", () => {
|
||||
expect(startMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("throws", () => {
|
||||
expect(error.message).toBe("Tried to start \"some-id\", but it is already being started.");
|
||||
});
|
||||
});
|
||||
|
||||
describe("when starting finishes", () => {
|
||||
beforeEach(async () => {
|
||||
await startMock.resolve(stopMock);
|
||||
|
||||
@ -13,6 +13,7 @@ export const getStartableStoppable = (
|
||||
let stop: Stopper;
|
||||
let stopped = false;
|
||||
let started = false;
|
||||
let starting = false;
|
||||
let startingPromise: Promise<Stopper> | Stopper;
|
||||
|
||||
return {
|
||||
@ -21,6 +22,12 @@ export const getStartableStoppable = (
|
||||
},
|
||||
|
||||
start: async () => {
|
||||
if (starting) {
|
||||
throw new Error(`Tried to start "${id}", but it is already being started.`);
|
||||
}
|
||||
|
||||
starting = true;
|
||||
|
||||
if (started) {
|
||||
throw new Error(`Tried to start "${id}", but it has already started.`);
|
||||
}
|
||||
@ -30,6 +37,7 @@ export const getStartableStoppable = (
|
||||
|
||||
stopped = false;
|
||||
started = true;
|
||||
starting = false;
|
||||
},
|
||||
|
||||
stop: async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user