         (when-not (= state :finished)
           (recur))))
     ch))
+
+(defn- api-promise
+  "Takes an API function which expects a channel as its first arg, followed by
+  the API functions other args. Returns a promise of the response the API
+  function puts on the channel.
+
+  This is a temporary shim to reuse the old API functions in the Om Next send."
+  [api-f & args]
+  (p/promise
+   (fn [resolve reject]
+     (let [ch (chan)]
+       (go-loop []
+         (let [[_ state data] (<! ch)]
+           (when (= state :success)
+             (resolve (:resp data)))
+           (when-not (= state :finished)
+             (recur))))
+       (apply api-f ch args)))))
 
 (defn- job-run-status [job-status-str]
   (case job-status-str

        (let [[expr cb] (de-alias-expression expr cb)
              ast (om-parser/expr->ast expr)]
          (cond
            ;; (branch-crumb-ast? ast) (get-branch-name cb ast query)
            (branch-runs-ast? ast) (get-branch-runs cb ast query)
            (= {:app/current-user [{:user/organizations [:organization/name :organization/vcs-type :organization/avatar-url]}]}
               expr)
            (let [ch (callback-api-chan

(ns frontend.send
  (:require [bodhi.aliasing :as aliasing]
            [bodhi.core :as bodhi]
            [cljs-time.coerce :as time-coerce]
            [cljs-time.core :as time]
            [cljs.core.async :refer [<! chan]]
            [clojure.set :refer [rename-keys]]
            [frontend.api :as api]
            [frontend.send.resolve :refer [resolve]]
            [frontend.utils.expr-ast :as expr-ast]
            [frontend.utils.vcs-url :as vcs-url]
            [om.next :as om-next]
            [om.next.impl.parser :as om-parser]
            [promesa.core :as p :include-macros true])
  (:require-macros [cljs.core.async.macros :as am :refer [go-loop]]))

(def ^:private ms-until-retried-run-retrieved 3000)
