title: asyncio: running task only if all other tasks are awaiting
body: <p>I am currently running some endless tasks using <code>asyncio.wait</code></p>
  <p>I need a special function to run when all the others are on <code>await</code></p>
  <pre><code>import asyncio 
  
  async def special_function():
      while True:
          # does some work, 
          # Passes control back to controller to run main_tasks
          # if they are no longer waiting.
          await asyncio.sleep(0)
  
  async def handler():
      tasks = [task() for task in main_tasks]
  
      # Adding the task that I want to run when all main_tasks are awaiting:
      tasks.append(special_function())
  
      await asyncio.wait(tasks)
  
  asyncio.get_event_loop().run_until_complete(handler())
  </code></pre>
  <p>How can I get  the <code>special_function</code> to only be run when all <code>main_tasks</code> are on <code>await</code>?</p>
  <hr />
  <h2>Edit:</h2>
  <p>What I mean by &quot;all <code>main_tasks</code> are on <code>await</code>&quot;: all <code>main_tasks</code> are not ready to continue, e.g. are in <code>asyncio.sleep(100)</code> or I/O bound and still waiting for data.</p>
  <p>Therefore the <code>main_tasks</code> cannot continue and the event loop runs the <code>special_function</code> while the tasks are in this state, NOT every iteration of the event loop.</p>
  <hr />
  <h2>Edit 2:</h2>
  <p>My use case:</p>
  <p>The <code>main_tasks</code> are updating a data structure with new data from web-sockets.</p>
  <p>The <code>special_function</code> transfers that data to another process upon an update signal from that process. (<code>multiprocessing</code> with shared variables and data structures)</p>
  <p>It needs to be the most up to date data it can be when it transfers, there cannot be pending updates from main_tasks.</p>
  <p>This is why I only want to run special_function when there are no main_tasks with new data available to be processed. (i.e. all waiting on <code>await</code>)</p>