MCPcopy Create free account
hub / github.com/electric-sql/electric / dispatchWake

Function dispatchWake

packages/agents-runtime/src/create-handler.ts:408–442  ·  view source on GitHub ↗
(
    notification,
    options
  )

Source from the content-addressed store, hash-verified

406 }
407
408 const dispatchWake: RuntimeRouter[`dispatchWake`] = (
409 notification,
410 options
411 ): void => {
412 const wakeLabel = notification.streamPath
413 const controller = new AbortController()
414 const wake: Promise<void> = Promise.resolve(
415 processWake(notification, {
416 ...wakeConfig,
417 ...options,
418 shutdownSignal: controller.signal,
419 })
420 )
421 .then(() => undefined)
422 .catch((err: unknown) => {
423 const wakeError = err instanceof Error ? err : new Error(String(err))
424 const handled = config.onWakeError?.(wakeError) === true
425 if (!handled) {
426 wakeErrors.push(wakeError)
427 }
428 runtimeLog.error(
429 `[agent-runtime]`,
430 `Error processing wake for ${notification.entity?.url}:`,
431 wakeError
432 )
433 })
434 .finally(() => {
435 pendingWakes.delete(wake)
436 pendingWakeLabels.delete(wake)
437 pendingWakeControllers.delete(wake)
438 })
439 pendingWakes.add(wake)
440 pendingWakeLabels.set(wake, wakeLabel)
441 pendingWakeControllers.set(wake, controller)
442 }
443
444 const isWakeActive: RuntimeRouter[`isWakeActive`] = (streamPath) =>
445 [...pendingWakeLabels.values()].includes(streamPath)

Callers

nothing calls this directly

Calls 6

processWakeFunction · 0.90
setMethod · 0.65
pushMethod · 0.45
errorMethod · 0.45
deleteMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected