title: Running a background worker in React Native Expo for intensive tasks
body: <p>I would like to create a background-worker/-service that is running in the background that executes jobs that are queued. For example if a user is downloading a image, receiving a message or uplading files.</p>
  <p>The idea would be like having a loop that waits for a semaphore to release:</p>
  <pre><code>class BackgroundWorker {
  
      async process() {
        while (true) {
          const job = await this.jobQueue.waitAsync(); // waits for a job being enqueued
          
          // process job...
        }
      }
  }
  </code></pre>
  <p>I saw in the expo documentation that it is possible to use the TaskManager or the BackgroundFetch but these classes are not guaranteed to be executed in the interval that you can specify (<a href="https://docs.expo.dev/versions/latest/sdk/task-manager/" rel="nofollow noreferrer">https://docs.expo.dev/versions/latest/sdk/task-manager/</a> and <a href="https://docs.expo.dev/versions/latest/sdk/background-fetch/" rel="nofollow noreferrer">https://docs.expo.dev/versions/latest/sdk/background-fetch/</a>). I was using the BackgroundFetch and set the minimumInterval to 10 seconds. It was executing the function every minute. I need a solution where I can react directly to events.</p>
  <p>Another question is, if it's possible to run these kind of workers in the background while the application is closed/terminated or running in the background.</p>