( handler: OutboxHandler, event: typeof outboxEvent.$inferSelect, timeoutMs: number = DEFAULT_HANDLER_TIMEOUT_MS )
| 520 | } |
| 521 | |
| 522 | function 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 |
no test coverage detected