Fork me on GitHub
#off-topic
<
2020-05-22
>
emccue07:05:50

(defn chan
  ([size]
   (ArrayBlockingQueue. size))
  ([]
   (chan 1)))

(defn >! [chan val]
  (.put chan val))

(defn <! [chan]
  (.take chan))

(defmacro go [& code]
  `(with-open [scope# (FiberScope/open (into-array FiberScope$Option []))]
     (let [c# (chan)]
       (.schedule scope# (reify Callable
                           (call [_]
                             (>! c# (do ~@code)))))
       c#)))

seancorfield16:05:47

They're getting rid of all the Fiber stuff and doing Loom via (virtual) Threads now so it'll all be "just like threads" except lightweight and you won't need to pool etc.

seancorfield16:05:13

(and targeting Java 17 for them... so it's still "years away")

emccue16:05:10

Thats.. a fairly large change isn't it

emccue16:05:37

i was wondering why there wasn't a Fiber class when i downloaded the last preview build

Alex Miller (Clojure team)17:05:29

java 17 is actually only like a year away at current schedule (at least for early builds)

Alex Miller (Clojure team)17:05:03

loom builds are based on that

seancorfield17:05:14

Yeah, I saw the new virtual threads stuff is available in 15ea. I was thinking of 17ga tho' since many folks wouldn't want to run non-LTS, non-GA builds in production. Looking at the schedule for 15ga, I guess 17ga would be September 2021 so it's only 18 months away right now...

bhauman20:05:10

this is big big

Alex Miller (Clojure team)20:05:24

I will temper my enthusiasm with my decade of waiting for it to appear

emccue20:05:55

I've been able to crash these early release jdks pretty easy with write contention on atoms

emccue20:05:26

(defn chan
  ([size]
   (ArrayBlockingQueue. size))
  ([]
   (chan 1)))

(defn >! [chan val]
  (.put chan val))

(defn <! [chan]
  (.take chan))

(defmacro go [& code]
  `(let [c# (chan)]
     (Thread/startVirtualThread
       (fn [] (>! c# (do ~@code))))
     c#))

emccue20:05:10

Hmm, what would the performance difference be between core.async chans and the java BlockingQueues

emccue20:05:38

Unlike a BlockingQueue core.async channels are designed to work with go blocks and do not block threads but instead have parking semantics.

emccue20:05:44

oh they just might not be needed

plexus07:05:32

yeah I'm guessing when Loom actually ships that you'll be able to use async/thread / <!! / >!! just fine, no real need for go blocks (at least in Clojure, still very useful sometimes in ClojureScript)

emccue07:05:08

yearly post opining that jvm fibers aren't finished yet

Aron08:05:28

something with fibers that they are not finished ever

Aron08:05:42

I know at least 2 other examples

krzyz16:05:32

@emccue Makes me wonder what will happen to all the async frameworks when it is finished.