Skip to content

Commit 44d71d6

Browse files
authored
Merge pull request #102 from windingtree/feat/open_close_db
feat: add open and close db to server package
2 parents ea08ab2 + 7a2c35f commit 44d71d6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/server/src/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CustomEvent, EventEmitter } from '@libp2p/interface/events';
99
import { NodeKeyJson, PeerOptions } from '@windingtree/sdk-types';
1010
import { centerSub, CenterSub } from '@windingtree/sdk-pubsub';
1111
import { decodeText } from '@windingtree/sdk-utils';
12-
import { StorageInitializer } from '@windingtree/sdk-storage';
12+
import { Storage, StorageInitializer } from '@windingtree/sdk-storage';
1313
import { createLogger } from '@windingtree/sdk-logger';
1414

1515
const logger = createLogger('Server');
@@ -65,6 +65,7 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
6565
private peerKey: NodeKeyJson;
6666
private libp2p?: Libp2p;
6767
private messagesStorageInit: StorageInitializer;
68+
private messagesStorage?: Storage;
6869

6970
/**
7071
* Creates an instance of CoordinationServer.
@@ -103,7 +104,8 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
103104
* @memberof CoordinationServer
104105
*/
105106
async start(): Promise<void> {
106-
const messagesStorage = await this.messagesStorageInit();
107+
this.messagesStorage = await this.messagesStorageInit();
108+
await this.messagesStorage.open();
107109

108110
const config: Libp2pOptions = {
109111
start: false,
@@ -115,7 +117,7 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
115117
connectionEncryption: [noise()],
116118
services: {
117119
pubsub: centerSub({
118-
messagesStorage,
120+
messagesStorage: this.messagesStorage,
119121
}),
120122
},
121123
connectionManager: {
@@ -151,6 +153,7 @@ export class CoordinationServer extends EventEmitter<CoordinationServerEvents> {
151153
* @memberof CoordinationServer
152154
*/
153155
async stop(): Promise<void> {
156+
await this.messagesStorage?.close();
154157
if (!this.libp2p) {
155158
throw new Error('libp2p not initialized yet');
156159
}

0 commit comments

Comments
 (0)