@langchain/langgraph
Version:
1 lines • 2.59 kB
Source Map (JSON)
{"version":3,"file":"runtime.cjs","names":["#drainReason"],"sources":["../../src/pregel/runtime.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/no-unused-vars - needed to resolve below link\nimport type { GraphDrained } from \"../errors.js\";\n\n/**\n * Run-scoped control surface for cooperative draining.\n *\n * Intended for a single graph run. Create a fresh {@link RunControl} per run;\n * reusing a control after {@link RunControl#requestDrain} leaves it drained.\n *\n * Safe to use from any concurrent context: the drain request is represented\n * by a single field write, so no synchronization is needed for this signal.\n * If more mutable state is added here, add synchronization.\n *\n * The intended use is hooking SIGTERM (or any external supervisor signal) to\n * {@link RunControl#requestDrain} so an in-flight graph run can stop cleanly\n * at the next superstep boundary and be resumed later from the saved\n * checkpoint.\n *\n * @example\n * ```typescript\n * import { RunControl, GraphDrained } from \"@langchain/langgraph\";\n *\n * const control = new RunControl();\n *\n * // In a signal handler, supervisor, etc.:\n * // control.requestDrain(\"sigterm\");\n *\n * try {\n * const result = await graph.invoke(input, { ...config, control });\n * if (control.drainRequested) {\n * // finished naturally on the same tick where drain was requested\n * }\n * } catch (e) {\n * if (e instanceof GraphDrained) {\n * // checkpoint saved; resume later with the same config\n * } else {\n * throw e;\n * }\n * }\n * ```\n */\nexport class RunControl {\n #drainReason: string | undefined = undefined;\n\n /**\n * Request that the current run drain cooperatively, stopping at the next\n * superstep boundary. Does not cancel work that is already running.\n *\n * @param reason - A short description of why the drain was requested.\n * Surfaced on the resulting {@link GraphDrained} error.\n */\n requestDrain(reason: string = \"shutdown\"): void {\n this.#drainReason = reason;\n }\n\n /** Whether a drain has been requested for this run. */\n get drainRequested(): boolean {\n return this.#drainReason !== undefined;\n }\n\n /** The reason passed to {@link RunControl#requestDrain}, if any. */\n get drainReason(): string | undefined {\n return this.#drainReason;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,aAAb,MAAwB;CACtB,eAAmC,KAAA;;;;;;;;CASnC,aAAa,SAAiB,YAAkB;AAC9C,QAAA,cAAoB;;;CAItB,IAAI,iBAA0B;AAC5B,SAAO,MAAA,gBAAsB,KAAA;;;CAI/B,IAAI,cAAkC;AACpC,SAAO,MAAA"}