code: def _create_auto_suggest_function(self, buffer):
          
          suggest_thread_running = [False]  # By ref.
  
          def async_suggestor():
              document = buffer.document
  
              # Don't start two threads at the same time.
              if suggest_thread_running[0]:
                  return
  
              # Don't suggest when we already have a suggestion.
              if buffer.suggestion or not buffer.auto_suggest:
                  return
  
              # Otherwise, get completions in other thread.
              suggest_thread_running[0] = True
  
              def run():
                  suggestion = buffer.auto_suggest.get_suggestion(self, buffer, document)
  
                  def callback():
                      suggest_thread_running[0] = False
  
                      # Set suggestion only if the text was not yet changed.
                      if buffer.text == document.text and \
                              buffer.cursor_position == document.cursor_position:
  
                          # Set suggestion and redraw interface.
                          buffer.suggestion = suggestion
                          self.invalidate()
                      else:
                          # Otherwise, restart thread.
                          async_suggestor()
  
                  if self.eventloop:
                      self.eventloop.call_from_executor(callback)
  
              self.eventloop.run_in_executor(run)
          return async_suggestor
docs: Create function for asynchronous auto suggestion.
          (AutoSuggest in other thread.)