Public Vars

Back

run! (clj)

(source)

function

(run! proc coll)
Runs the supplied procedure (via reduce), for purposes of side effects, on successive items in the collection. Returns nil

Examples

eponai/sulolive
(ns eponai.server.external.datomic
  (:require [com.stuartsierra.component :as component]
            [eponai.server.datomic-dev :as datomic-dev]
            [eponai.common.database :as db]
            [datomic.api :as datomic]
            [suspendable.core :as suspendable]
            [clojure.core.async :as async]
            [taoensso.timbre :refer [debug error]])
  (:import (java.util.concurrent BlockingQueue)))

  component/Lifecycle
  (start [this]
    (if (:conn this)
      this
      (let [conn (or provided-conn
                     (datomic-dev/create-connection db-url
                                                    {::datomic-dev/add-data? add-mocked-data?}))
            tx-listeners (atom {})
            control-chan (async/chan)
            tx-report-queue (datomic/tx-report-queue conn)]
        (async/thread
          (try
            (loop []
              (let [tx-report (.take ^BlockingQueue tx-report-queue)]
                (when-not (= ::finished tx-report)
                  (->>
                    (deref tx-listeners)
                    (vals)
                    (run!
                      (fn [{:keys [on-tx-report on-error]}]
                        (try
                          (on-tx-report tx-report)
                          (catch Throwable e
                            (error "Error in DatomicChat thread reading tx-report-queue: " e)
                            (try
                              (on-error e)
                              (catch Throwable e
                                (error "on-error threw exception, really?: " e))))))))
                  (recur))))
            (catch InterruptedException e
              (error "Error in DatomicChat thread reading tx-report-queue: " e)))
          (debug "Exiting Datomic async/thread..")
          (async/close! control-chan))
        (assoc this :conn conn
                    :control-chan control-chan
                    :tx-listeners tx-listeners
                    :tx-report-queue tx-report-queue))))
  (stop [this]
    (when-let [conn (:conn this)]
      (datomic/remove-tx-report-queue conn)
      ;; Adding ::finished to will eventually close the control-chan
      (.add ^BlockingQueue (:tx-report-queue this) ::finished)
      (let [[v c] (async/alts!! [(:control-chan this) (async/timeout 1000)])]
        (if (= c (:control-chan this))
          (debug "Datomic report-queue successfully stopped.")
          (debug "Datomic report-queue timed out when stopping.")))
      (datomic/release conn))
    (dissoc this :conn :control-chan :tx-listeners :tx-report-queue))
footprintanalytics/footprint-web
(ns metabase.driver.druid.client-test
  (:require [clojure.core.async :as a]
            [clojure.test :refer :all]
            [metabase.driver.druid.client :as druid.client]
            [metabase.driver.util :as driver.u]
            [metabase.query-processor :as qp]
            [metabase.query-processor.context.default :as default]
            [metabase.test :as mt]
            [metabase.timeseries-query-processor-test.util :as tqpt]))

(deftest query-cancelation-test
  (mt/test-driver :druid
    (tqpt/with-flattened-dbdef
      (let [query (mt/mbql-query checkins)]
        (mt/with-open-channels [running-chan (a/promise-chan)
                                cancel-chan  (a/promise-chan)]
          (with-redefs [druid.client/DELETE   (fn [& _]
                                                (a/>!! cancel-chan ::cancel))
                        druid.client/do-query (fn [& _]
                                                (a/>!! running-chan ::running)
                                                (Thread/sleep 5000)
                                                (throw (Exception. "Don't actually run!")))]
footprintanalytics/footprint-web
(ns metabase.driver.presto-test
  (:require [clj-http.client :as http]
            [clojure.core.async :as a]
            [clojure.string :as str]
            [clojure.test :refer :all]
            [honeysql.core :as hsql]
            [java-time :as t]
            [metabase.db.metadata-queries :as metadata-queries]
            [metabase.driver :as driver]
            [metabase.driver.presto :as presto]
            [metabase.driver.sql.query-processor :as sql.qp]
            [metabase.driver.util :as driver.u]
            [metabase.models.database :refer [Database]]
            [metabase.models.field :refer [Field]]
            [metabase.models.table :as table :refer [Table]]
            [metabase.query-processor :as qp]
            [metabase.test :as mt]
            [metabase.test.fixtures :as fixtures]
            [metabase.util :as u]
            [schema.core :as s]
            [toucan.db :as db]))

(deftest query-cancelation-test
  (mt/test-driver :presto
    (let [query (mt/mbql-query venues)]
      (mt/with-open-channels [running-chan (a/promise-chan)
                              cancel-chan  (a/promise-chan)]
        (with-redefs [http/delete            (fn [& _]
                                               (a/>!! cancel-chan ::cancel))
                      presto/fetch-next-page (fn [& _]
                                               (a/>!! running-chan ::running)
                                               (Thread/sleep 5000)
                                               (throw (Exception. "Don't actually run!")))]
          (let [out-chan (qp/process-query-async query)]
            ;; wait for query to start running, then close `out-chan`
            (a/go
              (a/<! running-chan)
              (a/close! out-chan)))
          (is (= ::cancel
                 (mt/wait-for-result cancel-chan 2000))))))))
pol-is/polisMath
;; @@
(ns sunset-canyon
  (:require [gorilla-plot.core :as plot]
            ;; Polis things
            [polismath.math.conversation :as conv]
            [polismath.runner :as runner]
            [polismath.system :as system]
            [polismath.conv-man :as conv-man]
            [clojure.core.matrix :as matrix]
            [gg4clj.core :as gg]
            [user]))
;; @@
;; =>
;;; {"type":"html","content":"<span class='clj-nil'>nil</span>","value":"nil"}
;; <=

;; @@
;; 90% of the time, this is fine
(do
  (runner/run! system/base-system {:math-env :dev})

  ;; If you ever want to run the vote or task pollers, see below
  ;(runner/run! system/poller-system {:math-env :dev :poll-from-days-ago 0.1})
  ;(runner/run! system/task-system {:math-env :preprod :poll-from-days-ago 3})
  
  ;; elide system from gorilla file (system shows env credentials; need to fix this)...
  nil)
yetibot/core
(ns yetibot.core.test.handler
  (:require
   [midje.sweet :refer [facts fact => =not=> contains provided]]
   [yetibot.core.handler :as h]
   [clojure.string :as s]
   [yetibot.core.interpreter :as i]
   yetibot.core.test.db
   yetibot.core.commands.echo
   [yetibot.core.chat :refer [chat-data-structure *adapter*]]
   [clojure.core.async :refer [<!!]]))

(facts
 "about handle-raw"
 (fact
  "it will run the raw command because it is a message and returns a successful,
   non-embedded result of the command and then dispatch the command response ..
   the related go channel always returns nil because of its use of (run!) <<
   maybe return result to make more testable ??"
  (let [cs {:adapter :slack
            :uuid :test
            :room "#C123"}
        user {:id 123 :username "greg" :yetibot? false}
        yb-user {:id 456 :username "yetibot" :yetibot? true}
        event-type :message
        body "!echo hello"]
    (binding [*adapter* (:adapter cs)]
      (<!! (h/handle-raw cs user event-type yb-user {:body body}))
      => nil
      (provided (h/dispatch-command-response
                 {:embedded? false, :error? false, :result "hello"})
                => :diddispatch))))
 
 (fact
  "it will always do nothing and return nil when the event type is not a message"
  (h/handle-raw nil nil :not-a-message nil {:body "some"}) => nil))