title: API Design that notifies Calling module and continues execution
body: <p>I am designing a python API which takes some parameters. My primary requirement for this API is that calling module should be notified in case of some event X and it should also wait for the execution to complete.</p>
  <p>I have already thought of passing a callback function to get executed on event X but I cannot do that since that method is tightly coupled to the callee.</p>
  <p>This is what I want to achieve:</p>
  <pre><code>test = API().run()
  </code></pre>
  <p>On Event X, control should come back to test and then I wait again on previous API.run to complete.</p>
  <p>So something like this</p>
  <pre><code>    while (waiting on run to complete) or (X does not happens):
           doX()
  </code></pre>
  <p>Here I somehow want API to communicate to me X has happened</p>