Skip to content

Commit 28eadc5

Browse files
committed
[connector] Connect/disconnect
1 parent 0116a87 commit 28eadc5

4 files changed

Lines changed: 12 additions & 16 deletions

File tree

src/@types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ export function createSynclet(
6868
export interface Connector {
6969
__brand: 'Connector';
7070
log(message: string, level?: LogLevel): void;
71-
start(): Promise<void>;
72-
stop(): Promise<void>;
71+
connect(): Promise<void>;
72+
disconnect(): Promise<void>;
7373
setAtom: (
7474
address: Address,
7575
atom: Atom,

src/core/connector.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const createConnector: typeof createConnectorDecl = async (
4040
}: ConnectorImplementations,
4141
options: ConnectorOptions = {},
4242
): Promise<ProtectedConnector> => {
43-
let started = false;
43+
let connected = false;
4444
let attachedSynclet: Synclet | undefined;
4545

4646
const id = options.id ?? getUniqueId();
@@ -60,19 +60,19 @@ export const createConnector: typeof createConnectorDecl = async (
6060

6161
log,
6262

63-
start: async () => {
64-
if (!started) {
65-
log('start');
63+
connect: async () => {
64+
if (!connected) {
65+
log('connect');
6666
await connect?.();
67-
started = true;
67+
connected = true;
6868
}
6969
},
7070

71-
stop: async () => {
72-
if (started) {
73-
log('stop');
71+
disconnect: async () => {
72+
if (connected) {
73+
log('disconnect');
7474
await disconnect?.();
75-
started = false;
75+
connected = false;
7676
}
7777
},
7878

@@ -143,8 +143,6 @@ export const createConnector: typeof createConnectorDecl = async (
143143
attachedSynclet = synclet;
144144
},
145145

146-
connect,
147-
disconnect,
148146
readAtom,
149147
readTimestamp,
150148
readHash,

src/core/protected.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export type Message = [
2222
export type ReceiveMessage = (message: Message, from: string) => Promise<void>;
2323

2424
export interface ProtectedConnector extends Connector {
25-
connect?: () => Promise<void>;
26-
disconnect?: () => Promise<void>;
2725
attachToSynclet(synclet: Synclet): void;
2826
readAtom(address: Address, context: Context): Promise<Atom | undefined>;
2927
readTimestamp(

src/core/synclet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export const createSynclet: typeof createSyncletDecl = (async (
294294
start: async () => {
295295
if (!started) {
296296
log('start');
297-
await connector.start();
297+
await connector.connect();
298298
await transport.connect?.(receiveMessage);
299299
started = true;
300300
await sync([]);

0 commit comments

Comments
 (0)