MCPcopy Index your code
hub / github.com/tinyplex/tinybase / createCustomSynchronizer

Function createCustomSynchronizer

src/synchronizers/index.ts:63–342  ·  view source on GitHub ↗
(
  store: MergeableStore,
  send: Send,
  registerReceive: (receive: Receive) => void,
  extraDestroy: () => void,
  requestTimeoutSeconds: number,
  onSend?: Send,
  onReceive?: Receive,
  onIgnoredError?: (error: any) => void,
  // undocumented:
  extra: {[methodName: string]: (...args: any[]) => any} = {},
)

Source from the content-addressed store, hash-verified

61};
62
63export const createCustomSynchronizer = (
64 store: MergeableStore,
65 send: Send,
66 registerReceive: (receive: Receive) => void,
67 extraDestroy: () => void,
68 requestTimeoutSeconds: number,
69 onSend?: Send,
70 onReceive?: Receive,
71 onIgnoredError?: (error: any) => void,
72 // undocumented:
73 extra: {[methodName: string]: (...args: any[]) => any} = {},
74): Synchronizer => {
75 let syncing: 0 | 1 = 0;
76 let persisterListener:
77 PersisterListener<PersistsEnum.MergeableStoreOnly> | undefined;
78 let sends = 0;
79 let receives = 0;
80
81 const pendingRequests: IdMap<
82 [
83 toClientId: IdOrNull,
84 handleResponse: (response: any, fromClientId: Id) => void,
85 ]
86 > = mapNew();
87
88 const getTransactionId = () => getUniqueId(11);
89
90 const sendImpl = (
91 toClientId: IdOrNull,
92 requestId: IdOrNull,
93 message: MessageEnum | any,
94 body: any,
95 ) => {
96 sends++;
97 onSend?.(toClientId, requestId, message, body);
98 send(toClientId, requestId, message, body);
99 };
100
101 const request = async <Response>(
102 toClientId: IdOrNull,
103 message: MessageEnum | any,
104 body: any,
105 transactionId: Id,
106 ): Promise<[response: Response, fromClientId: Id, transactionId: Id]> =>
107 promiseNew((resolve, reject) => {
108 const requestId = transactionId + DOT + getUniqueId(4);
109 const timeout = startTimeout(() => {
110 collDel(pendingRequests, requestId);
111 reject(
112 `No response from ${toClientId ?? 'anyone'} to ${requestId}, ` +
113 message,
114 );
115 }, requestTimeoutSeconds);
116 mapSet(pendingRequests, requestId, [
117 toClientId,
118 (response: Response, fromClientId: Id) => {
119 clearTimeout(timeout);
120 collDel(pendingRequests, requestId);

Callers 7

index.tsFile · 0.90
constructorMethod · 0.90
index.tsFile · 0.90
index.tsFile · 0.90
configureServerClientFunction · 0.90

Calls 14

mapNewFunction · 0.90
createCustomPersisterFunction · 0.90
mapGetFunction · 0.90
isNullFunction · 0.90
getChangesFromOtherStoreFunction · 0.70
sendImplFunction · 0.70
isAutoLoadingMethod · 0.65
isAutoSavingMethod · 0.65
getMergeableTableDiffMethod · 0.65
getMergeableRowDiffMethod · 0.65
getMergeableCellDiffMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…