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

Function runHandlerWithTimeout

apps/sim/lib/core/outbox/service.ts:522–548  ·  view source on GitHub ↗
(
  handler: OutboxHandler,
  event: typeof outboxEvent.$inferSelect,
  timeoutMs: number = DEFAULT_HANDLER_TIMEOUT_MS
)

Source from the content-addressed store, hash-verified

520}
521
522function runHandlerWithTimeout(
523 handler: OutboxHandler,
524 event: typeof outboxEvent.$inferSelect,
525 timeoutMs: number = DEFAULT_HANDLER_TIMEOUT_MS
526): Promise<void> {
527 const context: OutboxEventContext = {
528 eventId: event.id,
529 eventType: event.eventType,
530 attempts: event.attempts,
531 }
532
533 return new Promise((resolve, reject) => {
534 const timeout = setTimeout(() => {
535 reject(new OutboxHandlerTimeoutError(timeoutMs))
536 }, timeoutMs)
537
538 handler(event.payload, context)
539 .then((value) => {
540 clearTimeout(timeout)
541 resolve(value)
542 })
543 .catch((err) => {
544 clearTimeout(timeout)
545 reject(err)
546 })
547 })
548}
549
550/**
551 * Conditional terminal update scoped to the lease acquired at claim

Callers 1

runHandlerFunction · 0.85

Calls 2

handlerFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected