Skip to content

Commit b95a528

Browse files
committed
chore: update README
1 parent c2d1d92 commit b95a528

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

packages/sdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ replane.close();
259259

260260
### `replane.close()`
261261

262-
Gracefully shuts down the Replane client and cleans up resources. Subsequent method calls will throw. Use this in environments where you manage resource lifecycles explicitly (e.g. shutting down a server or worker).
262+
Gracefully shuts down the Replane client and cleans up resources. Subsequent method calls is a no-op, it's safe to call multiple times. Use this in environments where you manage resource lifecycles explicitly (e.g. shutting down a server or worker).
263263

264264
```ts
265265
// During shutdown

packages/sdk/tests/index.spec.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,31 @@ describe("createReplaneClient", () => {
19651965
// Config should still be initial since client is closed
19661966
expect(client.get("config1")).toBe("initial");
19671967
});
1968+
1969+
it("should be safe to call close() multiple times", async () => {
1970+
clientPromise = createClient();
1971+
const connection = await mockServer.acceptConnection();
1972+
1973+
await connection.push({
1974+
type: "init",
1975+
configs: [{ name: "config1", overrides: [], value: "value1" }],
1976+
});
1977+
1978+
const client = await clientPromise;
1979+
await sync();
1980+
1981+
// First close
1982+
expect(() => client.close()).not.toThrow();
1983+
1984+
// Second close should also not throw
1985+
expect(() => client.close()).not.toThrow();
1986+
1987+
// Third close for good measure
1988+
expect(() => client.close()).not.toThrow();
1989+
1990+
// Client should still be usable for reading cached data
1991+
expect(client.get("config1")).toBe("value1");
1992+
});
19681993
});
19691994
});
19701995

@@ -2024,10 +2049,18 @@ describe("createInMemoryReplaneClient", () => {
20242049
expect(client.get("null")).toBe(null);
20252050
});
20262051

2027-
it("should have a no-op close method", () => {
2052+
it("should be safe to call close() multiple times", () => {
20282053
const client = createInMemoryReplaneClient({ config1: "value1" });
20292054

2055+
// First close
2056+
expect(() => client.close()).not.toThrow();
2057+
2058+
// Second close should also not throw
20302059
expect(() => client.close()).not.toThrow();
2060+
2061+
// Third close for good measure
2062+
expect(() => client.close()).not.toThrow();
2063+
20312064
// Config should still work after close
20322065
expect(client.get("config1")).toBe("value1");
20332066
});
@@ -2145,14 +2178,23 @@ describe("restoreReplaneClient", () => {
21452178
expect(client.get("config1", { default: "fallback" })).toBe("actual");
21462179
});
21472180

2148-
it("should have a no-op close method", () => {
2181+
it("should be safe to call close() multiple times", () => {
21492182
const snapshot: ReplaneSnapshot<Record<string, unknown>> = {
21502183
configs: [{ name: "config1", value: "value1", overrides: [] }],
21512184
};
21522185

21532186
const client = restoreReplaneClient({ snapshot });
21542187

2188+
// First close
2189+
expect(() => client.close()).not.toThrow();
2190+
2191+
// Second close should also not throw
21552192
expect(() => client.close()).not.toThrow();
2193+
2194+
// Third close for good measure
2195+
expect(() => client.close()).not.toThrow();
2196+
2197+
// Config should still work after close
21562198
expect(client.get("config1")).toBe("value1");
21572199
});
21582200

0 commit comments

Comments
 (0)