title: koa js: What does "next" refer to, and can cascading be implemented differently?
body: <p>I'm trying to wrap my head around the way koajs cascades by awaiting on "next()" before resuming request processing. As far as I can tell, "next" simply refers to the next sequential app.use() in the script.</p>
  
  <p>Can someone more familiar with koajs confirm this? For example, would this code (modified from koajs.com) still work (foo and bar used to be "next")?</p>
  
  <pre><code>app.use(async (ctx, foo) =&gt; {
    const start = Date.now();
    await foo();
    const ms = Date.now() - start;
    ctx.set('X-Response-Time', `${ms}ms`);
  });
  
  app.use(async (ctx, bar) =&gt; {
    const start = Date.now();
    await bar();
    const ms = Date.now() - start;
    console.log(`${ctx.method} ${ctx.url} - ${ms}`);
  });
  
  app.use(async ctx =&gt; {
    ctx.body = 'Hello World';
  });
  </code></pre>
  
  <p>Or is there something magical about using "next" (besides good semantics)? I'm assuming not, and the behavior is just dependent on the argument order in the function.</p>
  
  <p>If this is the case, then how is it possible to control the flow from one app.use() to another? For example something like this pseudo code:</p>
  
  <pre><code>   app.use(async (ctx, a, b) =&gt; {
      if (!ctx.something) {
      await a();
      } else {
      await b();
      }
     }
  
     let a = app.use(.....);
     let b = app.use(.....);
  </code></pre>
  
  <p>Any help is appreciated, and also, feel free to point me to an appropriate resource if I've missed something simple.</p>