MCPcopy
hub / github.com/simstudioai/sim / WaitBlockHandler

Class WaitBlockHandler

apps/sim/executor/handlers/wait/wait-handler.ts:99–197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97 * up once `resumeAt` is reached. Async caps at 30 days.
98 */
99export class WaitBlockHandler implements BlockHandler {
100 canHandle(block: SerializedBlock): boolean {
101 return block.metadata?.id === BlockType.WAIT
102 }
103
104 async execute(
105 ctx: ExecutionContext,
106 block: SerializedBlock,
107 inputs: Record<string, any>
108 ): Promise<BlockOutput> {
109 return this.executeWithNode(ctx, block, inputs, { nodeId: block.id })
110 }
111
112 async executeWithNode(
113 ctx: ExecutionContext,
114 block: SerializedBlock,
115 inputs: Record<string, any>,
116 nodeMetadata: {
117 nodeId: string
118 loopId?: string
119 parallelId?: string
120 branchIndex?: number
121 branchTotal?: number
122 originalBlockId?: string
123 isLoopNode?: boolean
124 executionOrder?: number
125 }
126 ): Promise<BlockOutput> {
127 const isAsync = inputs.async === true || inputs.async === 'true'
128 const timeValue = Number.parseFloat(inputs.timeValue || '10')
129 const timeUnit = isAsync ? inputs.timeUnitLong || 'minutes' : inputs.timeUnit || 'seconds'
130
131 if (!Number.isFinite(timeValue) || timeValue <= 0) {
132 throw new Error('Wait amount must be a positive number')
133 }
134
135 if (!isWaitUnit(timeUnit)) {
136 throw new Error(`Unknown wait unit: ${timeUnit}`)
137 }
138
139 if (isAsync && timeUnit === 'seconds') {
140 throw new Error('Seconds are not allowed in async mode')
141 }
142
143 const waitMs = Math.round(timeValue * UNIT_TO_MS[timeUnit])
144
145 if (isAsync) {
146 if (waitMs > MAX_ASYNC_WAIT_MS) {
147 throw new Error('Wait time exceeds maximum of 30 days')
148 }
149 } else if (waitMs > MAX_INPROCESS_WAIT_MS) {
150 throw new Error(
151 'Wait time exceeds maximum of 5 minutes; enable async mode to wait up to 30 days'
152 )
153 }
154
155 if (!isAsync) {
156 const completed = await sleep(waitMs, {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected