Asynchronous http poll

2018-05-08 Thread Brjánn Ljótsson
Hi!

I'm writing a server-side (S1) function that initiates an action on another
server (S2) and regularly checks if the action has finished
(failed/completed). It should also be possible for a client to ask S1 for
the status of the action performed by S2.

My idea is to create an uid on S1 that represents the action and the uid is
returned to the client. S1 then asynchronously polls S2 for action status
and updates an atom with the uid as key and status as value. The client can
then request the status of the uid from S1. Below is a link to my proof of
concept code (without any code for the client requests or timeout guards) -
and it is my first try at writing code using core.async.

https://gist.github.com/brjann/d80f1709b3c17ef10a4fc89ae693927f

The code can be tested with for example (start-poll) or (repeatedly 10
start-poll) to test the behavior when multiple requests are made.

The code seems to work, but is it a correct use of core.async? One thing
I'm wondering is if the init-request and poll functions should use threads
instead of go-blocks, since the http requests may take a few hundred
milliseconds and many different requests (with different uids) could be
made simultaneously. I've read that "long-running" tasks should not be put
in go blocks. I haven't figured out how to use threads though.

I would be thankful for any input!

Best wishes,
Brjánn Ljótsson

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Understanding GraalVM and Clojure

2018-05-08 Thread Daniel Carleton
I was interested to see if a native-image binary could be run on AWS 
Lambda, and a superficial example does at least:

https://github.com/uwcpdx/clombda

On Tuesday, May 1, 2018 at 12:22:41 AM UTC-7, Khalid Jebbari wrote:
>
> The ClojureScript unit tests pass in the JavaScript engine that comes with 
> GraalVM 1.0.0-rc1
>
> https://t.co/WiNHWhv04v (via @Mike Fikes on Twitter)
>
> Le mar. 1 mai 2018 à 06:33, Nathan Fisher  > a écrit :
>
>> Is there a runnable language test suite that is used to verify CLJ, CLJS, 
>> and CLR compatibility? Thinking something similar to RubySpec that could be 
>> used to validate the completeness/gaps in a particular implementation (eg 
>> GraalVM).
>> On Sun, Apr 29, 2018 at 7:16 AM, Khalid Jebbari > > wrote:
>>
>>> I've read it, it's really interesting. Alex Miller mentioned on Twitter 
>>> that they'll work on removing some limitations over time. @Alex, can you 
>>> confirm and expand a bit more ?
>>>
>>> Le sam. 28 avr. 2018 à 23:14, Nathan Fisher >> > a écrit :
>>>
 Another interesting post on Clojure and Graal

 https://www.innoq.com/en/blog/native-clojure-and-graalvm/
 On Sat, Apr 28, 2018 at 10:01 AM, Khalid Jebbari >>> > wrote:

> Thank you for the link.
>
> Le sam. 28 avr. 2018 à 00:35, Egg Syntax  > a écrit :
>
>> Karin Meier has done some experimentation using Clojure on GraalVM to 
>> call R and Python, and has a blog post 
>> 
>>  and repo 
>> 
>>  that 
>> you may find interesting.
>>
>>
>> On Thursday, April 19, 2018 at 6:00:14 AM UTC-4, Khalid Jebbari wrote:
>>>
>>> Hello,
>>>
>>> Oracle has just announced GraalVM 1.0 release candidate: 
>>> https://blogs.oracle.com/developers/announcing-graalvm
>>>
>>> It mentions a few JVM-based language but not Clojure (maybe just 
>>> because of popularity).
>>> - Does it mean Clojure is not "compatible" with GraalVM ? 
>>> - Does it mean Clojure needs to be reimplemented in terms of 
>>> GraalVM's Truffle framework ?
>>> - Does it mean Clojure can be run as a native binary with fast 
>>> startup time and minimized memory footprint ?
>>>
>>> If someone with some knowledge could explain to me the relationships 
>>> between Clojure and GraalVM ? Bonus points if Alex Miller answers and 
>>> share 
>>> the plans, if any, about their integration/interaction.
>>>
>>> Thanks a lot in advance. really curious to understand more.
>>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient 
>> with your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>>
> You received this message because you are subscribed to a topic in the 
>> Google Groups "Clojure" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/clojure/iBY6hwqqp5c/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> clojure+u...@googlegroups.com .
>
>
>> For more options, visit https://groups.google.com/d/optout.
>>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com 
> 
> Note that posts from new members are moderated - please be patient 
> with your first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com 
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google 
> Groups "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to clojure+u...@googlegroups.com .
> For more options, visit https://groups.google.com/d/optout.
>
 -- 
 - sent from my mobile

 -- 
 You received this message because you are subscribed to the Google
 Groups "Clojure" group.
 To post to this group, send email to clo...@googlegroups.com 
 
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com 
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed

[ANN] Fun-map: put your code into a map, it turns value whenever you need them

2018-05-08 Thread Robert Luo


*- Github link: https://github.com/robertluo/fun-map*


>From the project's README:


In clojure, code is data, the fun-map turns value fetching function call into 
map value accessing.

For example, when we store a delay as a value inside a map, we may want to 
retrieve the value wrapped inside, not the delayed object itself, i.e. a 
`deref` automatically be called when accessed by map's key. This way, we can 
treat it as if it is a plain map, without the time difference of when you store 
and when you retrieve. There are libraries exist for this purpose commonly 
known as *lazy map*.

Likewise, we may want to store future object to a map, then when accessing it, 
it's value retrieving will happen in another thread, which is useful when you 
want parallels realizing your values. Maybe we will call this *future map*?

How about combine them together? Maybe a *delayed future map*?

Also there is widely used library as [prismatic 
graph](https://github.com/plumatic/plumbing), store functions as map values, by 
specify which keys they depend, this map can be compiled to traverse the map.

One common thing in above scenarios is that if we store something in a map as a 
value, it is intuitive that we care just its underlying real value, no matter 
when it can be accessed, or what its execution order. As long as it won't 
change its value once referred, it will be treated as a plain value.

## Usage

### Simplest scenarios

Any value implements `clojure.lang.IDeref` interface in a fun-map will 
automatically `deref` when accessed by its key. In fact, it will be a *deep 
deref*, keeps `deref` until it reaches a none ref value.

```clojure
(require '[robertluo.fun-map :refer [fun-map fnk touch]])

(def m (fun-map {:a 4 :b (delay (println "accessing :b") 10)}))

(:b m)

;;"accessing :b"
;;=> 10

(:b m)
;;=> 10 ;Any function as a value will be just be invoked once

```

Or future objects as values that will be accessed at same time.

```clojure
(def m (fun-map {:a (future (do (Thread/sleep 1000) 10))
 :b (future (do (Thread/sleep 1000) 20))}))

(touch m)

;;=> {:a 10, b 20} ;futures in :a, :b are evaluated parallelly
```

### Where fun begins

A function in fun-map and has `:wrap` meta as `true` takes the map itself as 
the argument, return value will be *unwrapped* when accessed by key.

`fnk` macro will be handy in many cases, it destructs args from the map, and 
set the `:wrap` meta.

```clojure
(def m (fun-map {:xs (range 10)
 :count-keys ^:wrap (fn [m] (count (keys m)))
 :sum (fnk [xs] (apply + xs))
 :cnt (fnk [xs] (count xs))
 :avg (fnk [sum cnt] (/ sum cnt))}))
(:avg m)
;;=> 9/2

(:count-keys m)
;;=> 5
```

Notice the above example looks like a prismatic graph, with the difference that 
a fun-map remains a map, so it can be composed like a map, like `merge` with 
other map, `assoc` plain value, etc.

Though you should watch out that fun-map does not compute dependencies of keys 
and the function in a value will just be invoked once, re-assoc a value will 
not cause its dependents re-invoke.

Fun-map also can be nested, so you could `get-in` or `update-in`.

### Trace the function calls

Accessing values of fun-map can be traced, which is very useful for logging, 
debugging and make it a extremely lightweight (< 100 LOC now) life cycle system.

```clojure
(def invocations (atom []))

(def m (fun-map {:a 3 :b (fnk [a] (inc a)) :c (fnk [b] (inc b))}
 :trace-fn (fn [k v] (swap! invocations conj [k v]

(:c m) ;;accessing :c will in turn accessing :b
@invocations
;;=> [[:b 4] [:c 5]]
```

### Life cycle map for orderred shutdown

Using above trace feature, it is very easy to support a common scenario of 
[components](http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded).
 The starting of components is simply accessing them by name, `life-cycle-map` 
will make it haltable (implemented `java.io.Closeable` also) by reverse its 
starting order.

```clojure
(def system
  (life-cycle-map
{:component/a
(fnk []
  (reify java.io.Closeable
(close [_]
  (println "halt :a"
 :component/b
 (fnk [:component/a]
   (reify java.io.Closeable
 (close [_]
   (println "halt :b"}))

 (touch system) ;;start the entire system, you may also just start part of 
system
 (halt! system)
 ;;halt :b
 ;;halt :a
```

`robertluo.fun-map.Haltable` protocol can be extended to your type of 
component, or you can implements `java.io.Closeable` interface to indicate it 
is a life cycle component.


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.goo

[ANN] fun-map: put your code into this map, it turns value when you access it

2018-05-08 Thread Robert Luo
*Github Link: https://github.com/robertluo/fun-map*

It is a lazy map:

(def m (fun-map {:a 4 :b (delay (println "accessing :b") 10)}))


and can also be a future map:

(def m (fun-map {:a (future (do (Thread/sleep 1000) 10))
 :b (future (do (Thread/sleep 1000) 20))}))


or mixed:

(def m (fun-map {:a (future (do (Thread/sleep 1000) 10))
 :b (delay 20)}))


or cascading function calls:

(def m (fun-map {:xs (range 10)
 :count-keys ^:wrap (fn [m] (count (keys m)))
 :sum (fnk [xs] (apply + xs))
 :cnt (fnk [xs] (count xs))
 :avg (fnk [sum cnt] (/ sum cnt))}))


or even a light weight system can be halted in order:

(def system
  (life-cycle-map
{:component/a
 (fnk []
  (reify java.io.Closeable
(close [_]
  (println "halt :a"
 :component/b
 (fnk [:component/a]
   (reify java.io.Closeable
 (close [_]
   (println "halt :b"}))

(touch system) ;;start the system

(halt! system)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ANN] CIDER 0.17 (Andalucía) is out!

2018-05-08 Thread Bozhidar Batsov
On 7 May 2018 at 23:07, Gregg Reynolds  wrote:

> Looks awesome!
>
> Any idea when 1.0 will be out?
>

Not really. Most likely when the internal improvements section of the
roadmap is completed
https://github.com/clojure-emacs/cider/blob/master/ROADMAP.md, but work is
progressing slowly.


>
> On Mon, May 7, 2018, 2:55 PM Bozhidar Batsov  wrote:
>
>> Hey everyone!
>>
>> I'm happy to share with you that CIDER finally made it all the way
>> to Andalucía! This was a massive release that added a lot of new
>> functionality and improved much of the existing one. Here are the most
>> important changes in a nutshell:
>>
>> - improved ClojureScript support
>> - the ability to display images in the REPL
>> - support for deps.edn "projects"
>> - support for test selectors
>> - much of the core functionality on the Clojure side was been extracted
>> to a stand-alone library https://github.com/clojure-emacs/orchard
>> (that's step towards socket REPL support and stronger cross-editor
>> collaboration)
>>
>> And here are all the details:
>>
>> ### New features
>>
>> * [#2248](https://github.com/clojure-emacs/cider/pull/2248):
>> `cider-repl` can now display recognized images in the REPL buffer.
>> * [#2172](https://github.com/clojure-emacs/cider/pull/2172): Render
>> diffs for expected / actual test results.
>> * [#2167](https://github.com/clojure-emacs/cider/pull/2167): Add new
>> defcustom `cider-jdk-src-paths`. Configure it to connect stack trace links
>> to Java source code.
>> * [#2161](https://github.com/clojure-emacs/cider/issues/2161): Add new
>> interactive command `cider-eval-defun-to-point` which is bound to `C-c C-v
>> (C-)z`. It evaluates the current top-level form up to the point.
>> * [#2113](https://github.com/clojure-emacs/cider/issues/2113): Add new
>> interactive commands `cider-eval-last-sexp-in-context` (bound to `C-c
>> C-v (C-)c`) and `cider-eval-sexp-at-point-in-context` (bound to `C-c C-v
>> (C-)b`).
>> * Add new interactive command `cider-repl-set-type`.
>> * [#1976](https://github.com/clojure-emacs/cider/issues/1976): Add new
>> interactive command `cider-connect-clojurescript`.
>> * Add a menu for `cider-browse-ns-mode`.
>> * [#2160](https://github.com/clojure-emacs/cider/issues/2160): Make it
>> possible to configure the default `*print-level*` and `*print-length*` via
>> defcustoms (`cider-repl-print-level` and `cider-repl-print-length`).
>> * New interactive command `cider-cheatsheet` allows you to browse the
>> Clojure Cheatsheet with an Emacs interface.
>> * [#2191](https://github.com/clojure-emacs/cider/issues/2191): Add
>> support for jacking-in just with the `clojure` command-line tool and
>> `tools.deps`.
>> * Make it possible to start a Nashorn ClojureScript REPL.
>> * [#2235](https://github.com/clojure-emacs/cider/pull/2235): Make the
>> REPL ignore blank input rather than evaluating.
>> * [#2241](https://github.com/clojure-emacs/cider/pull/2241): Make
>> `cider-test-ediff` diff eval'ed values.
>> * Add support for shadow-cljs to `cider-jack-in`.
>> * [#2244](https://github.com/clojure-emacs/cider/issues/2244): Display
>> the REPL type in the modeline.
>> * [#2238](https://github.com/clojure-emacs/cider/pull/2238): Allow
>> specifying predicates for entries in `cider-jack-in-lein-plugins` and
>> `cider-jack-in-nrepl-middlewares`.
>> * Add support for test selectors. If test all or all loaded is called
>> with a prefix ask for filter test selectors in the minibuffer and only run
>> those tests in the project which match the filters. Add variation of test
>> namespace which asks for filter selectors the same way and only runs a
>> subset of the namespace tests.
>> * Add a configuration variable allowing to control whether server output
>> should be redirected to the REPL (`cider-redirect-server-
>> output-to-repl`).
>>
>> ### Bugs Fixed
>>
>> * [#1913](https://github.com/clojure-emacs/cider/issues/1913): Fix
>> `cider-toggle-buffer-connection` to allow cycling of connection and
>> restoring all connections in cljc buffers.
>> * [#2148](https://github.com/clojure-emacs/cider/issues/2148): Fix `jump
>> to definition` working properly when remote `cider-jack-in` and
>> `cider-connect`.
>> * Font-lock failed assertions even in tests that were evaluated
>> interactively.
>> * [#2102](https://github.com/clojure-emacs/cider/issues/2102): Make
>> `cider-format-buffer` handle mismatched parens gracefully.
>>
>> ### Changes
>>
>> * [#2163](https://github.com/clojure-emacs/cider/issues/2163): Add
>> `cider-browse-spec-regex`, and changed `cider-browse-spec-all` to use it.
>> * [#2029](https://github.com/clojure-emacs/cider/pull/2154): Make
>> cider-doc use cider-browse-spec functionality to print the spec part of the
>> doc buffer
>> * [#2151](https://github.com/clojure-emacs/cider/pull/2151): Improve
>> formatting of spec in `cider-doc` buffer.
>> * Remove support for CLJX.
>> * Fix `cider-eval-region` masking `clojure-refactor-map` in
>> `cider-repl-mode`.
>> * [#2171](https://github.com/clo