@kumiai/rpc 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/hub-mux.js +17 -6
  2. package/package.json +6 -6
package/lib/hub-mux.js CHANGED
@@ -127,9 +127,6 @@ const warnReceiveEnded = (ended)=>{
127
127
  * whose `subscribe` registers synchronously is registered by the time `retain` returns — the
128
128
  * subscribe-then-pull ordering the commit lane depends on is unchanged.
129
129
  */ const attemptSubscribe = async (topicID, options, attempt)=>{
130
- subscriptions.set(topicID, {
131
- kind: 'asking'
132
- });
133
130
  try {
134
131
  // Inside the try, and awaited: `subscribe` may reject OR throw synchronously (the type
135
132
  // allows `void`), and the old code's `Promise.resolve(...).catch()` caught only the first.
@@ -164,6 +161,18 @@ const warnReceiveEnded = (ended)=>{
164
161
  await attemptSubscribe(topicID, options, attempt + 1);
165
162
  }
166
163
  };
164
+ const startSubscribe = (topicID, options)=>{
165
+ // Not `Promise.withResolvers`: this runs on Hermes too. `attemptSubscribe` never rejects.
166
+ let settle = ()=>{};
167
+ const ready = new Promise((resolve)=>{
168
+ settle = resolve;
169
+ });
170
+ subscriptions.set(topicID, {
171
+ kind: 'asking',
172
+ ready
173
+ });
174
+ void attemptSubscribe(topicID, options, 0).finally(settle);
175
+ };
167
176
  const retain = (topicID, options)=>{
168
177
  refcount.set(topicID, (refcount.get(topicID) ?? 0) + 1);
169
178
  // Gated on the SUBSCRIPTION, never on the refcount. A topic held, or currently being asked
@@ -171,7 +180,7 @@ const warnReceiveEnded = (ended)=>{
171
180
  // hold it, and the data structure must not pretend otherwise.
172
181
  const state = subscriptions.get(topicID);
173
182
  if (state == null) {
174
- void attemptSubscribe(topicID, options, 0);
183
+ startSubscribe(topicID, options);
175
184
  return;
176
185
  }
177
186
  if (state.kind !== 'refused') return;
@@ -185,7 +194,7 @@ const warnReceiveEnded = (ended)=>{
185
194
  if (state.permanent && (options?.retention == null || options.retention === state.options?.retention)) {
186
195
  return;
187
196
  }
188
- void attemptSubscribe(topicID, options, 0);
197
+ startSubscribe(topicID, options);
189
198
  };
190
199
  /**
191
200
  * Clear a latched refusal so the topic is asked for once more, on the caller's word that the
@@ -209,7 +218,7 @@ const warnReceiveEnded = (ended)=>{
209
218
  const { options } = state;
210
219
  subscriptions.delete(topicID);
211
220
  if ((refcount.get(topicID) ?? 0) > 0) {
212
- void attemptSubscribe(topicID, options, 0);
221
+ startSubscribe(topicID, options);
213
222
  }
214
223
  };
215
224
  /**
@@ -557,6 +566,8 @@ const warnReceiveEnded = (ended)=>{
557
566
  // A fetch of a refused topic would die of `NotSubscribedError` — the SYMPTOM, naming the mux's
558
567
  // own failure to subscribe as if it were the caller's mistake. The latched refusal is raised
559
568
  // instead, so what reaches the host is the reason.
569
+ const state = subscriptions.get(params.topicID);
570
+ if (state?.kind === 'asking') await state.ready;
560
571
  assertSubscribable(params.topicID);
561
572
  // Called on `hub`, not through a detached reference: a LogHub is often a class, and
562
573
  // an unbound method loses its receiver.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kumiai/rpc",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "High-level MLS-aware group RPC for Enkaku: bus broadcast/anycast/gather plus directed RPC over the pub/sub hub",
5
5
  "keywords": [
6
6
  "rpc",
@@ -26,11 +26,11 @@
26
26
  "lib/*"
27
27
  ],
28
28
  "dependencies": {
29
- "@enkaku/client": "^0.22.2",
30
- "@enkaku/protocol": "^0.22.2",
31
- "@enkaku/server": "^0.22.2",
32
- "@enkaku/transport": "^0.22.2",
33
- "@kokuin/token": "^0.6.2",
29
+ "@enkaku/client": "^0.22.3",
30
+ "@enkaku/protocol": "^0.22.3",
31
+ "@enkaku/server": "^0.22.3",
32
+ "@enkaku/transport": "^0.22.3",
33
+ "@kokuin/token": "^0.6.4",
34
34
  "@kumiai/broadcast": "^0.12.0",
35
35
  "@kumiai/hub-protocol": "^0.12.0",
36
36
  "@kumiai/hub-tunnel": "^0.12.0",