Clojure

New Releases with a Better Kotlin API, Dataflow for Clojure and Faster Web Actors

Today we have released minor updates to Quasar, Pulsar and Comsat. The releases contain bug fixes, and some new features including an improved Kotlin API, dataflow variables for Clojure and fast implementations of Web Actors on top of Undertow and Netty.

Elegant fibers and channel selection with Kotlin

Quasar 0.7.0 introduced a natural Kotlin API (that feels like Erlang) for Quasar actors. This release includes a nice API for working with fibers and channels (which feels like Go):

Creating and starting a fiber in Kotlin is now a no-brainer with the fiber syntax in co.paralleluniverse.kotlin:

fiber {
  // The fiber will be created and will start executing this body
}

fiber goes hand-in-hand with a new and elegant select syntax for selecting on multiple channels:

val ch1 = Channels.newChannel<Int>(1)
val ch2 = Channels.newChannel<Int>(1)

assertTrue (
    fiber {
        select(Receive(ch1), Send(ch2, 2)) {
            it
        }
    }.get() is Send
)

ch1.send(1)

assertTrue (
    fiber {
        select(Receive(ch1), Send(ch2, 2)) {
            when (it) {
                is Receive -> it.msg
                is Send -> 0
                else -> -1
            }
        }
    }.get() == 1
)}

See the Quasar release notes for further details and the list of bugs fixed.

Dataflow Variables

Pulsar now has a new API for dataflow variables (which have so far been accessible only in the Java API).

Dataflow, or reactive programming, is a computation described by composing variables whose value may be set (and possibly changed) at any given time, without concern for when these values are set. Pulsar provides two dataflow primitives: vals, created with df-val, and vars, created with df-var. A val is a dataflow constant. It can have its value set once, and read multiple times. A var is a dataflow variable. It can have it’s value set multiple times, and every new value can trigger the re-computation of other vars. You can also set a var to retain historical values.

Here is a simple example of using vals and vars:

(let [a (df-val)
      x (df-var)
      y (df-var #(* @a @x)) ; this var has a formula
      z (df-var #(+ @a @x))
      r (df-var #(let [v (+ @a @y @z)] ; a formula with side-effects
                      (println "res: " v)
                      v))
      f (fiber
          (loop [i 0]
            (when (< i 5)
              (sleep 50)
              (x i) ; sets the value of x
              (recur (inc i)))))]
    (sleep 10)
    (a 3) ; triggers everything by setting a
    (join f))

In this examples, vars y and z, are dependent on val a and var x, and will have their values recomputed – after a is set – whenever x changes.

See the Pulsar release notes for further details and the list of bugs fixed.

Comsat 0.5.0: Web Actors go Undertow and Netty

Comsat is a set of Quasar integration modules for various web-related libraries. In addition to library integrations, Comsat includes Web Actors, an API for writing interactive web services (with support for plain HTTP and/or web sockets and/or SSE) as Quasar actors. So far, web actors have been implemented on top of servlets, and could therefore run on any standard servlet container. Comsat 0.5.0 adds two new Web Actors deployment options: native Undertow and Netty. The two new implementations have better performance than the servlet-based implementation. Benchmarks will follow!

See the Release Notes for further details and the list of bugs fixed.

Enjoy!

Fabio Tudone

Fabio Tudone is a software developer at Parallel Universe, tirelessly looking for ways to write better code.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button