   (case command
     (interactive (company-begin-backend 'company-ycmd-backend))
     (prefix (company-ycmd-get-prefix))
-    (candidates (company-ycmd-get-candidates arg))
+    (candidates
+     (cons :async
+           (lambda (cb) (cb (company-ycmd-get-candidates arg))))
+     (company-ycmd-get-candidates arg))
     (meta (company-ycmd-get-metadata arg))
     (annotation (company-ycmd-get-annotation arg))
     (no-cache 't))) ; Don't cache. It interferes with fuzzy matching.

(defun company-ycmd-get-annotation (candidate)
  (format " [%s]" (get-text-property 0 'kind candidate)))

(defun company-ycmd-grab (regexp &optional expression limit)
  (when (looking-back regexp limit t)
    (or (match-string-no-properties (or expression 0)) "")))

(defun company-ycmd-get-prefix ()
  (and (memq major-mode company-ycmd-modes)
       buffer-file-name
       (ycmd-running?)
       (not (company-in-string-or-comment))
       
       (let* ((candidates (company-ycmd-candidates))
              (prefix (company-grab-symbol-cons "\\.\\|->\\|::" 2)))
         (setq company-ycmd-last-candidates candidates)
         (if candidates prefix))))

(defun company-ycmd-get-candidates (prefix)
  company-ycmd-last-candidates)

(defun company-ycmd-backend (command &optional arg &rest ignored)
  (interactive (list 'interactive))

(defcustom company-ycmd-modes '(c++-mode python-mode csharp-mode)
  "The list of modes for which company-ycmd will attempt completions.")

(defun company-ycmd-construct-candidate (src)
  (let ((candidate (assoc-default 'insertion_text src)))
    (dolist (prop company-ycmd-completion-properties candidate)
