Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ts/src/actions/Execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import type {Action} from "../action";

export const packetType = "execution";

function nowMicros(): bigint {
return BigInt(Math.floor((performance.timeOrigin + performance.now()) * 1000));
}

function buildParams(execution: ActionExecutionRequest, func: RuntimeFunctionProps): (PlainValue | undefined)[] {
return (func.parameters || []).map(param => {
const field = execution.parameters?.fields?.[param.runtimeName];
Expand Down Expand Up @@ -38,13 +42,13 @@ export function handle(action: Action, execution: ActionExecutionRequest): void
matchedConfig: conf,
};

const startedAt = BigInt(Date.now());
const startedAt = nowMicros();
const funcHandler = func.handler;
const allParams: (PlainValue | undefined)[] =
funcHandler.length === params.length + 1 ? [context as PlainValue, ...params] : params;

Promise.resolve(funcHandler(...allParams)).then((value: PlainValue) => {
const finishedAt = BigInt(Date.now());
const finishedAt = nowMicros();
action.stream!.requests.send(ActionTransferRequest.create({
data: {
oneofKind: "result",
Expand All @@ -62,7 +66,7 @@ export function handle(action: Action, execution: ActionExecutionRequest): void
})).catch(err => console.error("Failed to send execution result:", err));

}).catch((error: unknown) => {
const finishedAt = BigInt(Date.now());
const finishedAt = nowMicros();
const isRuntimeError = error instanceof RuntimeError;
action.stream!.requests.send(ActionTransferRequest.create({
data: {
Expand Down