1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { runVal } from "https://esm.town/v/std/runVal";
export let limitedVal = (async () => {
// Throws: Error: An untrusted val attempted to access secrets and was blocked.
// const limit = await @rlimit.limit({
// max: 100,
// interval: "10s",
// cost: 5,
// });
const limit = await runVal("rlimit.limit", {
max: 100,
interval: "10s",
cost: 5,
});
if (!limit.ok) {
throw new Error("limit reached");
}
console.log("limit ok", limit);
// continue with expensive operation
})();
// Forked from @rlimit.limitedVal