rollup.run
Convenience request loop: repeatedly finishes the previous request and dispatches the next one to your handlers.
Usage
import { } from "@cartesi/rollup";
const = new ();
await .({
(, ) {
.(.);
return true;
},
(, ) {
.(.);
},
});Returns
Promise<void>, and where it settles depends on which side you are running:
- Inside a Cartesi Machine the loop never ends on its own — the application is meant to keep serving requests forever. The promise only settles if
finishfails (for example the device was closed), and then it rejects with that error. - On the host mock it also resolves once the inputs listed in
CMT_INPUTSrun out, which is the natural end of a test session. Any otherfinishfailure still rejects.
So a host test can simply await rollup.run(...) and then assert on the outputs, with no catch in the way.
Parameters
handlers
- Type:
RunHandlers
An object with an optional handler per request type. Both receive (request, rollup) and may be synchronous or async:
type = {
?: (
: AdvanceRequest,
: ,
) => boolean | void | <boolean | void>;
?: (
: InspectRequest,
: ,
) => boolean | void | <boolean | void>;
};The handler's result decides the request's fate:
| Handler outcome | Effect |
|---|---|
returns true or undefined | request accepted |
returns false | request rejected |
| throws | exception emitted as a report, request rejected |
| no handler for the request type | request rejected |
See Handling Requests for the semantics of accept/reject.
run takes exactly one handler per request type. To split a request kind across several independently written handlers, fold them with chain or broadcast — see Composing Handlers. Those compose handlers that must return a real boolean, which is assignable here.