Public Vars

Back

deliver (clj)

(source)

function

(deliver promise val)
Delivers the supplied value to the promise, releasing any pending derefs. A subsequent call to deliver on a promise will have no effect.

Examples

replikativ/datahike
(ns datahike.http.writer
  "Remote writer implementation for datahike.http.server through datahike.http.client."
  (:require [datahike.writer :refer [PWriter create-writer create-database delete-database]]
            [datahike.http.client :refer [request-json] :as client]
            [datahike.json :as json]
            [datahike.tools :as dt :refer [throwable-promise]]
            [taoensso.timbre :as log]
            [clojure.core.async :refer [promise-chan put!]]))

(defmethod create-database :datahike-server
  [& args]
  (let [p (throwable-promise)
        {:keys [writer] :as config} (first args)]
    ;; redirect call to remote-peer as writer config
    (deliver p (try (->
                     (request-json :post
                                   "create-database-writer"
                                   writer
                                   (vec (concat [(-> config
                                                     (assoc :remote-peer writer)
                                                     (dissoc :writer))]
                                                (rest args))))
                     (dissoc :remote-peer))
                    (catch Exception e
                      e)))
    p))

(defmethod delete-database :datahike-server
  [& args]
  (let [p (throwable-promise)
        {:keys [writer] :as config} (first args)]
    ;; redirect call to remote-peer as writer config
    (deliver p (try
                 (-> (request-json :post
                                   "delete-database-writer"
                                   writer
                                   (vec (concat [(-> config
                                                     (assoc  :remote-peer writer)
                                                     (dissoc :writer))]
                                                (rest args))))
                     (dissoc :remote-peer))
                 (catch Exception e
                   e)))
    p))
clojure/core.typed
(ns ^:skip-wiki clojure.core.typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  (:require [#?(:clj clojure.core.typed
                :cljs cljs.core.typed)
             :refer [defalias] :as t]))

(defalias
  ^{:doc "A Clojure promise (see clojure.core/{promise,deliver})."
    :forms '[(Promise t)]}
  t/Promise 
  (t/TFn [[x :variance :invariant]]
         (t/Rec [p]
                (t/I (t/Deref x)
                     (clojure.lang.IBlockingDeref x)
                     clojure.lang.IPending
                     [x -> (t/U nil p)]))))
typedclojure/typedclojure
(ns ^:no-doc typed.ann.clojure
  "Type annotations for the base Clojure distribution."
  #?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
  (:require [clojure.core :as cc]
            [typed.clojure :as t]
            #?(:clj [typed.ann-macros.clojure :as macros])
            #?(:clj typed.ann.clojure.jvm) ;; jvm annotations
            #?(:clj clojure.core.typed))
  #?(:clj
     (:import (clojure.lang PersistentHashSet PersistentList
                            APersistentMap #_IPersistentCollection
                            #_ITransientSet
                            IRef)
              (java.util Comparator Collection))))

#?(:clj
(t/defalias
  ^{:doc "A Clojure promise (see clojure.core/{promise,deliver})."
    :forms '[(Promise x)]}
  t/Promise 
  (t/TFn [[x :variance :invariant]]
         (t/I (t/Deref x)
              (clojure.lang.IBlockingDeref x)
              clojure.lang.IPending
              ;; FIXME I think this might be an implementation detail.
              [x :-> (t/Nilable (t/Promise x))]))))

#?@(:cljs [] :default [
cc/promise (t/All [x] [:-> (t/Promise x)])
cc/deliver (t/All [x] [(t/Promise x) x :-> (t/Nilable (t/Promise x))])
])
clojure-vim/neovim-client
(ns neovim-client.1.api.buffer-ext-test
  (:require [clojure.core.async :as async]
            [clojure.test :as test :refer [deftest use-fixtures is]]
            [neovim-client.1.api :as api]
            [neovim-client.1.api.buffer :as api.buffer]
            [neovim-client.1.api.buffer-ext :as api.buffer-ext]
            [neovim-client.nvim :as client.nvim]
            [neovim-client.test-helper :refer [with-neovim]]))

(deftest get-lines-async
  (with-neovim
    (let [{:keys [in out]} *neovim*
          conn (client.nvim/new* 1 in out false)
          p (promise)]
      (api/command conn "norm ifoo\nbar\nbaz\nqux")
      (api.buffer-ext/get-lines-async
        conn
        (api/get-current-buf conn)
        1 3
        #(deliver p %))
      (is (= ["bar" "baz"] @p)))))
stefonweblog/stefon
  (:require [clojure.test :refer :all]
            [midje.sweet :refer :all]
            [clojure.core.async :as async :refer :all]
            [stefon.shell.kernel :as kernel]
            [stefon.shell.plugin :as plugin]))

      (let [new-channel (chan)
            receivefn (plugin/generate-receive-fn new-channel)
            system-atom (atom {:stefon/system (kernel/generate-system)})
            result (promise)
            xx (receivefn system-atom
                          (fn [system-atom msg] (deliver result msg)))
            xx (>!! new-channel {:fu :bar})]