Skip to content

Commit be7af30

Browse files
committed
feat: 🎸 improve stop routine
1 parent b96d1ca commit be7af30

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

src/__demos__/json-crdt-server/routes/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const createServices = async () => {
4444
const kv = new ClassicLevel<string, Uint8Array>(path, {valueEncoding: 'view'});
4545
await kv.open();
4646
store = new LevelStore(<any>kv);
47-
await kv.close();
4847
}
4948
const services = new Services({store});
5049
return services;

src/__demos__/json-crdt-server/services/Services.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ export class Services {
1919
this.presence = new PresenceService();
2020
this.blocks = new BlocksServices(this, store, blocks);
2121
}
22+
23+
async stop() {
24+
await this.blocks.stop();
25+
}
2226
}

src/__demos__/json-crdt-server/services/blocks/BlocksServices.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,8 @@ export class BlocksServices {
254254
if (blocksToDelete <= 0) return;
255255
await this.store.removeOldest(blocksToDelete);
256256
}
257+
258+
public async stop() {
259+
await this.store.stop?.();
260+
}
257261
}

src/__demos__/json-crdt-server/services/blocks/store/level/LevelStore.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,8 @@ export class LevelStore implements types.Store {
288288
} catch {}
289289
}
290290
}
291+
292+
public async stop() {
293+
await this.kv.close();
294+
}
291295
}

src/__demos__/json-crdt-server/services/blocks/store/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ export interface Store {
176176
* @returns Number of blocks and batches.
177177
*/
178178
stats(): {blocks: number; batches: number};
179+
180+
stop?(): Promise<void>;
179181
}
180182

181183
export interface StoreCreateResult {

0 commit comments

Comments
 (0)