title: Is it possible to trigger a longer running background task with Next JS?
body: <p>Next JS seems to automatically "clean up" API scripts using some logic after they are called (I'm assuming it's some period of time after the "res" is called back.  Is it possible to keep the script running for an indeterminate period of time after the res call back so that it would stay active until some longer running triggered background activity (like a slow render) is completed?</p>
  
  <p>Simple example, an endpoint that could be "polled" to start a task while it's processing and will eventually respond with the completed result:</p>
  
  <p><code>api/myscript</code></p>
  
  <p>code:</p>
  
  <pre><code>
  var result = null
  var processing = true
  
  export default (req, res) =&gt; {
    if (result) {
      res.end(result)
    } else if (!processing) {
      new Promise((result, reject) =&gt; {
        exec(cmd, ("ffmpeg -takeareallylongtime", stdout, stderr) =&gt; {
        if (error) {
          reject(error);
        }
        else {
          resolve("All done");
        }
      })})
      .then(_ =&gt; {
        result = "All done!"
      })
      .catch(_ =&gt; {
        result = "I'm sorry to have failed you."
      })
      res.end("Started task")
    } else {
      res.end("Still processing...")
    }
  }
  </code></pre>
  
  <p>The behavior I'm seeing is that the runner kicks off, the client polls periodically and gets a valid status back, and at some point during the processing the page gets purged:</p>
  
  <p><code>[ event ] disposing inactive page(s)</code></p>
  
  <p>and the global values tracking result are cleared.</p>