MCPcopy Index your code
hub / github.com/cloudflare/capnweb / resolve

Method resolve

src/rpc.ts:199–243  ·  view source on GitHub ↗
(resolution: StubHook)

Source from the content-addressed store, hash-verified

197 private onBrokenRegistrations?: number[];
198
199 resolve(resolution: StubHook) {
200 // TODO: Need embargo handling here? PayloadStubHook needs to be wrapped in a
201 // PromiseStubHook awaiting the embargo I suppose. Previous notes on embargoes:
202 // - Resolve message specifies last call that was received before the resolve. The introducer is
203 // responsible for any embargoes up to that point.
204 // - Any further calls forwarded by the introducer after that point MUST immediately resolve to
205 // a forwarded call. The caller is responsible for ensuring the last of these is handed off
206 // before direct calls can be delivered.
207
208 if (this.localRefcount == 0) {
209 // Already disposed (canceled), so ignore the resolution and don't send a redundant release.
210 resolution.dispose();
211 return;
212 }
213
214 this.resolution = resolution;
215 this.sendRelease();
216
217 if (this.onBrokenRegistrations) {
218 // Delete all our callback registrations from this session and re-register them on the
219 // target stub.
220 for (let i of this.onBrokenRegistrations) {
221 let callback = this.session.onBrokenCallbacks[i];
222 let endIndex = this.session.onBrokenCallbacks.length;
223 resolution.onBroken(callback);
224 if (this.session.onBrokenCallbacks[endIndex] === callback) {
225 // Oh, calling onBroken() just registered the callback back on this connection again.
226 // But when the connection dies, we want all the callbacks to be called in the order in
227 // which they were registered. So we don't want this one pushed to the back of the line
228 // here. So, let's remove the newly-added registration and keep the original.
229 // TODO: This is quite hacky, think about whether this is really the right answer.
230 delete this.session.onBrokenCallbacks[endIndex];
231 } else {
232 // The callback is now registered elsewhere, so delete it from our session.
233 delete this.session.onBrokenCallbacks[i];
234 }
235 }
236 this.onBrokenRegistrations = undefined;
237 }
238
239 if (this.activePull) {
240 this.activePull.resolve();
241 this.activePull = undefined;
242 }
243 }
244
245 async awaitResolution(): Promise<RpcPayload> {
246 if (!this.activePull) {

Callers

nothing calls this directly

Calls 4

sendReleaseMethod · 0.95
disposeMethod · 0.65
onBrokenMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected