This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-01
Channels
- # announcements (6)
- # atom-editor (4)
- # babashka (59)
- # beginners (51)
- # bristol-clojurians (6)
- # calva (5)
- # cider (22)
- # clara (6)
- # cljfx (28)
- # clojure (182)
- # clojure-australia (1)
- # clojure-berlin (1)
- # clojure-dev (21)
- # clojure-europe (12)
- # clojure-italy (8)
- # clojure-nl (7)
- # clojure-norway (13)
- # clojure-uk (20)
- # clojurescript (2)
- # code-reviews (24)
- # conjure (9)
- # cursive (9)
- # datomic (35)
- # defnpodcast (45)
- # fulcro (18)
- # graalvm (3)
- # graphql (1)
- # hugsql (1)
- # jobs (3)
- # jobs-discuss (2)
- # klipse (1)
- # leiningen (1)
- # malli (5)
- # membrane (4)
- # off-topic (7)
- # portal (2)
- # reitit (30)
- # remote-jobs (1)
- # rewrite-clj (5)
- # ring (2)
- # shadow-cljs (25)
- # test-check (2)
- # tools-deps (5)
- # vrac (26)
- # xtdb (17)
Thanks. It seems we have a gap for CLJS.
hello all, in thread macro execution, is there any way to stop it if any of step fails?
This might be a good technique to know: https://medium.com/appsflyer/railway-oriented-programming-clojure-and-exception-handling-why-and-how-89d75cc94c58
do you mean ->
or ->>
? then no. there is a some->
which can be used in a similar manner if your functions catch exceptions (or whatever your notion of failure) and return nil. it might be worth your time to build a little system similar to either
type or something similar
What is the opposite of async/alt!
? That is, how to retrieve a value from the slowest channel of several?
unless you provide a timeout and at that point you inspect for the last before the timeout?
that could be a neat exercise. sounds quite difficult to do and handle edge cases and not arbitrarily wait
I see. Then what's the easiest way to implement debouncing? If I have a function work
that might return too quickly to put in a loop:
(async/go-loop
(work)
(recur))
How do I modify the loop so that each iteration will take at least 1 second? (So that work
will not be called more frequently than once per second)and its possible it might take up to a second? Usually these situations you can wait on a timeout channel for a second and recur with the understanding that work
usually takes up an incredibly small amount of time
I think debouncing is usually done with one of the buffers that drops
like a chan
with a sliding-buffer
this doesn't sound like a good usage for core.async. If you're arbitrarily blocking you should probably submit this to an executor service. and there are scheduled ones that might handle this for you
I assume by debouncing you're in cljs?
debouncing is also built into Google Closure library
I came up with this that could work:
(async/go-loop
(let [ch (async/timeout 1000)]
(work)
(<! ch))
(recur))
another thing, if (work)
can take hours or return instantly, it seems like perhaps you just wait a second regardless and waiting a second is appropriate if work is instantaneous and completely negligible if work took hours
check out https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html#scheduleAtFixedRate-java.lang.Runnable-long-long-java.util.concurrent.TimeUnit- scheduleWithFixedDelay
. I think that fits your bill
Looks promising. So I guess these schedules do not have clojure wrappers and are used with Java interops?
correct. but the designers of Clojure have made interop pretty nice and clojure functions implement all of the goodness so that you can just basically (.scheduleWithFixedDelay executor-service work 0 1 TimeUnit/Second)
and you now only have to read the javadocs directly and not some wrapper's docs and then the javadocs backing them to figure out what's going on
Any hints on what might be causing > Caused by: java.lang.IllegalArgumentException: No implementation of method: :urls of protocol: #'clojure.java.classpath/URLClasspath found for class: jdk.internal.loader.ClassLoaders$AppClassLoader are GREATLY appreciated. Trying to avoid posting long stacktrace in this channel, all the context info is in https://github.com/juxt/joplin/issues/117
I had this issue earlier and ended up getting it to work by using this`(:use [clojure.pprint :as pp])`
Note that :use
is frowned upon
In an ns
form (:require [clojure.pprint :as pp])
(avoid :use
-- it refers in every symbol from the namespace, like :refer :all
, which is also frowned upon). In the REPL (require '[clojure.pprint :as pp])
there are a handful of things that are "auto-referred" in the repl, like pprint
in code, you'll need to require them however
that list is defined at https://github.com/clojure/clojure/blob/master/src/clj/clojure/main.clj#L355-L359
I expect this to append new entry, but it just resets it to a single :data/:indexes entry
(defn insert [table record id-key]
(let [db (read-db)
new-db {:data {id-key record}
:indexes [(count (get db :data)) table ]}]
new-db))
(write-db {})
(write-db (insert :hello {:name :hello :stock 100} 2))
(write-db (insert :hello {:name :hello :stock 100} 3))
;; => {:data {:hello {:name :hello, :stock 100}}, :indexes [1 :hello]}
(write-db (insert :hello {:name :hello :stock 100} :hello))
;; => {:data {:hello {:name :hello, :stock 100}}, :indexes [1 :hello]}
@mksybr What do write-db
and read-db
do? Also, you can use triple-backticks to format blocks of code to make them easier to read:
Like this block
Is easier to read
(def memory-db (atom {}))
(defn read-db [] @memory-db)
(defn write-db [new-db]
(reset! memory-db new-db))
@mksybr Since write-db
is just resetting the atom to the value it is given, and insert
is just returning a single hash map with :data
and :indexes
, I'm not sure what you expected to happen?
new-db
in insert
doesn't include any of the previous data so your DB isn't going to grow.
Perhaps you want write-db
to (swap! memory-db merge new-db)
instead?
Or perhaps insert
should return a larger data structure?
(you'll also have a race condition if you start using threads, since your insert
function could be called multiple times before write-db
so multiple :indexes
will have the same value of (count (get db :data))