title: How can we create asynchronous API in django?
body: <p>I want to create a third party chatbot API which is asynchronous and replies "ok" after 10 seconds pause.</p>
  
  <pre><code>import time
  
  def wait():
      time.sleep(10)
      return "ok"
  
  # views.py
  def api(request):
      return wait()
  </code></pre>
  
  <p>I have tried celery for the same as follows where I am waiting for celery response in view itself:</p>
  
  <pre><code>import time
  from celery import shared_task
  
  @shared_task
  def wait():
      time.sleep(10)
      return "ok"
  
  # views.py
  def api(request):
      a = wait.delay()
      work = AsyncResult(a.id)
      while True:
          if work.ready():
             return work.get(timeout=1)
  </code></pre>
  
  <p>But this solution works synchronously and makes no difference. How can we make it asynchronous without asking our user to keep on requesting until the result is received?</p>