feat(client): pipeline sends on the fetch's answer

Sends target an answer before it settles (Host.vowSend), so the fetch
and every send cross in one update call. Add icp.yaml for icp-cli, the
successor to dfx.

Generated-by: Claude Code (claude-opus-5-5)
This commit is contained in:
dckc committed 2026-11-18 05:53:10 -06:00
1 parent 1177fc86b6
commit da6c3f02ce
7 files changed
+197 -58

No files matched your search

+30 -18
View File
@@ -65,27 +65,39 @@ export const openPeer = async ({ module, seed, carry }, canisterId) => {
await pump();
if (!wasm.client_session_open()) throw Error('session did not open');
/** Wait for the pending call's answer, carrying frames as needed. */
const settle = async () => {
const slotOf = (status, what) => {
if (status < 0) throw Error(`${what}: ${decoder.decode(staged())}`);
return status;
};
/** Stage what the Host queued, then carry it until the canister is quiet. */
const flush = async () => {
check(wasm.client_outbound(), 'outbound');
await pump();
const kind = wasm.client_result_kind();
if (kind === 0) throw Error('no answer after the canister went quiet');
if (kind === 3) throw Error('broken');
return kind;
};
/** Read a settled answer, or throw. */
const valueOf = slot => {
const kind = wasm.client_result_kind(slot);
if (kind === 0) throw Error(`answer ${slot} still pending after the canister went quiet`);
if (kind === 3) throw Error(`answer ${slot} broke`);
return kind === 2 ? Number(wasm.client_result_integer(slot)) : { slot };
};
/**
* An answer: what `fetch` or `send` will settle to. Sends can target one
* before it settles; nothing crosses the wire until `flush`.
*
* @typedef {{ slot: number }} Answer
*/
return freeze({
/** Fetch the capability published as `name` and make it the target. */
async fetch(name) {
check(withBytes(encoder.encode(name), wasm.client_fetch), 'fetch');
await settle();
check(wasm.client_adopt(), 'adopt');
},
/** Send `verb` to the target; resolve to its integer answer. */
async send(verb) {
check(withBytes(encoder.encode(verb), wasm.client_send), 'send');
await settle();
return Number(wasm.client_result_integer());
},
/** @returns {Answer} the capability published as `name` */
fetch: name => ({ slot: slotOf(withBytes(encoder.encode(name), (p, n) => wasm.client_fetch(p, n)), 'fetch') }),
/** @returns {Answer} `target`'s answer to `verb` */
send: (target, verb) => ({
slot: slotOf(withBytes(encoder.encode(verb), (p, n) => wasm.client_send(target.slot, p, n)), 'send'),
}),
flush,
/** @param {Answer} answer */
valueOf: answer => valueOf(answer.slot),
});
};