Home / Function/ onSendHookRunner() — fastify Function Reference

onSendHookRunner() — fastify Function Reference

Architecture documentation for the onSendHookRunner() function in hooks.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  88644d4c_dc8e_7fa6_ed0b_2b6917b5db8d["onSendHookRunner()"]
  57bfad3b_e85a_1ebf_2702_a13bb6484083["hooks.js"]
  88644d4c_dc8e_7fa6_ed0b_2b6917b5db8d -->|defined in| 57bfad3b_e85a_1ebf_2702_a13bb6484083
  style 88644d4c_dc8e_7fa6_ed0b_2b6917b5db8d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/hooks.js lines 278–321

function onSendHookRunner (functions, request, reply, payload, cb) {
  let i = 0

  function next (err, newPayload) {
    if (err) {
      cb(err, request, reply, payload)
      return
    }

    if (newPayload !== undefined) {
      payload = newPayload
    }

    if (i === functions.length) {
      cb(null, request, reply, payload)
      return
    }

    let result
    try {
      result = functions[i++](request, reply, payload, next)
    } catch (error) {
      cb(error, request, reply)
      return
    }
    if (result && typeof result.then === 'function') {
      result.then(handleResolve, handleReject)
    }
  }

  function handleResolve (newPayload) {
    next(null, newPayload)
  }

  function handleReject (err) {
    if (!err) {
      err = new FST_ERR_SEND_UNDEFINED_ERR()
    }

    cb(err, request, reply, payload)
  }

  next()
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does onSendHookRunner() do?
onSendHookRunner() is a function in the fastify codebase, defined in lib/hooks.js.
Where is onSendHookRunner() defined?
onSendHookRunner() is defined in lib/hooks.js at line 278.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free