kinetex - v1.0.0-rc.1
    Preparing search index...

    Function composeAround

    • Compose multiple around hooks into one using the "onion" model.

      Each hook wraps the next, forming a chain where:

      • The highest priority hook wraps closest to next (innermost)
      • The lowest priority hook wraps closest to the caller (outermost)

      Execution order (example with 3 hooks):

      hook0 (outermost)
        → hook1
          → hook2 (innermost)
            → next()
            ← hook2 returns
          ← hook1 returns
        ← hook0 returns
      

      Parameters

      • ...hooks: AroundHook[]

        AroundHooks to compose (applied in priority order)

      Returns AroundHook

      Single composed AroundHook

      const timing = (ctx, next) => {
      const start = Date.now();
      return next().finally(() => {
      console.log(`Duration: ${Date.now() - start}ms`);
      });
      };

      const auth = (ctx, next) => {
      ctx.request.headers.Authorization = `Bearer ${getToken()}`;
      return next();
      };

      const composed = composeAround(timing, auth);