S2 take once in a bundle too, Go and TypeScript
A bundle holder takes an ask once through the runtime's create with the ask's bound as the key's time to live: stdio.KeptState.TakeOnce and TypeScript takeOnce; stdio.TakenState and TakenKey are the one name, which process refers to. Builds: design 47 H2 §775, §820; H-A-359
This commit is contained in:
@@ -1034,4 +1034,22 @@ async function newTest5(): Promise<void> {
|
||||
async function newTest6(): Promise<void> {
|
||||
const { state, CHUNK_BYTES } = await import("../dist/state/index.js");
|
||||
await assert.rejects(state("s").put("k", { text: "x".repeat(CHUNK_BYTES) }), /512 KiB/);
|
||||
// design 47 H2 §775, H-A-359: a holder given the same ask id twice acts once
|
||||
const { takeOnce, useStateChannel } = await import("../dist/state/index.js");
|
||||
const created = new Set<string>();
|
||||
const asked: unknown[] = [];
|
||||
useStateChannel({
|
||||
ask: async (method: string, params: unknown) => {
|
||||
asked.push([method, params]);
|
||||
const p = params as { key: string };
|
||||
if (created.has(p.key)) throw Object.assign(new Error("exists"), { code: -32010 });
|
||||
created.add(p.key);
|
||||
return { revision: 1 };
|
||||
},
|
||||
watch: async () => {},
|
||||
} as never);
|
||||
assert.equal(await takeOnce("git", "a-7", 600_000), true);
|
||||
assert.equal(await takeOnce("git", "a-7", 600_000), false);
|
||||
assert.deepEqual(asked[0], ["mesh/state.create", { state: "taken", key: "git.a-7", value: { seat: "git", ask: "a-7" }, ttl_seconds: 600 }]);
|
||||
await assert.rejects(takeOnce("git", "", 1000), /is not an ask id/);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user