mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Make startable-stoppable also restartable
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
bcf1a2aaf0
commit
9b48478c2d
@ -39,6 +39,12 @@ describe("getStartableStoppable", () => {
|
||||
expect(startMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("when started again, throws", () => {
|
||||
expect(() => {
|
||||
actual.start();
|
||||
}).toThrow("Tried to start something that has already started.");
|
||||
});
|
||||
|
||||
it("does not stop yet", () => {
|
||||
expect(stopMock).not.toHaveBeenCalled();
|
||||
});
|
||||
@ -58,10 +64,24 @@ describe("getStartableStoppable", () => {
|
||||
}).toThrow("Tried to stop something that has already stopped.");
|
||||
});
|
||||
|
||||
it("when started again, throws for restart being YAGNI with logical blind spots", () => {
|
||||
expect(() => {
|
||||
describe("when started again", () => {
|
||||
beforeEach(() => {
|
||||
startMock.mockClear();
|
||||
|
||||
actual.start();
|
||||
}).toThrow("Tried to restart something that has stopped.");
|
||||
});
|
||||
|
||||
it("starts", () => {
|
||||
expect(startMock).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("when stopped, stops", () => {
|
||||
stopMock.mockClear();
|
||||
|
||||
actual.stop();
|
||||
|
||||
expect(stopMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -12,22 +12,26 @@ export const getStartableStoppable = (
|
||||
return {
|
||||
start: () => {
|
||||
if (started) {
|
||||
throw new Error("Tried to restart something that has stopped.");
|
||||
throw new Error("Tried to start something that has already started.");
|
||||
}
|
||||
|
||||
stopped = false;
|
||||
|
||||
dispose = startAndGetStopCallback();
|
||||
|
||||
started = true;
|
||||
},
|
||||
|
||||
stop: () => {
|
||||
if (stopped) {
|
||||
throw new Error("Tried to stop something that has already stopped.");
|
||||
}
|
||||
|
||||
if (!started) {
|
||||
throw new Error("Tried to stop something that has not started yet.");
|
||||
}
|
||||
|
||||
if (stopped) {
|
||||
throw new Error("Tried to stop something that has already stopped.");
|
||||
}
|
||||
started = false;
|
||||
|
||||
dispose();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user