convex
Version:
Client for the Convex Cloud
47 lines (46 loc) • 1.45 kB
JavaScript
;
import { jsonToConvex } from "../../values/index.js";
import { createError, logToConsole } from "../logging.js";
export class ActionManager {
constructor() {
this.inflightActions = /* @__PURE__ */ new Map();
}
request(message) {
const result = new Promise((resolve, reject) => {
this.inflightActions.set(message.requestId, {
message,
onResult: resolve,
onFailure: reject
});
});
return result;
}
onResponse(response) {
const actionInfo = this.inflightActions.get(response.requestId);
if (actionInfo === void 0) {
return;
}
this.inflightActions.delete(response.requestId);
const udfPath = actionInfo.message.udfPath;
for (const line of response.logLines) {
logToConsole("info", "action", udfPath, line);
}
if (response.success) {
actionInfo.onResult(jsonToConvex(response.result));
} else {
logToConsole("error", "action", udfPath, response.result);
actionInfo.onFailure(createError("action", udfPath, response.result));
}
}
hasInflightActions() {
return this.inflightActions.size > 0;
}
restart() {
for (const [actionId, actionInfo] of this.inflightActions) {
this.inflightActions.delete(actionId);
const udfPath = actionInfo.message.udfPath;
actionInfo.onFailure(createError("action", udfPath, "Transient error"));
}
}
}
//# sourceMappingURL=action_manager.js.map