Note that there are some explanatory texts on larger screens.

plurals
  1. POClojure Midje 'provided' When Using 'pcalls'
    text
    copied!<p>I'm reasonably new to Clojure, and am trying to parallelize some calls to a function.</p> <p>Let's say I have a map as follows:</p> <pre><code>{:a 1 :b 2 :c 3} </code></pre> <p>and I want to use the keys and values as arguments of a function called my-function, with the function called for each key/value pair. I could use <code>doseq</code> as below:</p> <pre><code>(doseq [entry my-map] (my-function (key entry) (val entry))) </code></pre> <p>I then decide I want the calls to my-function to be in parallel (in my actual situation my-function will be making rest calls which are independent from each other, and so I want to do them in parallel). I came up with the following:</p> <pre><code>(apply pcalls (map #(partial my-function (key %) (val %)) my-map)) </code></pre> <p>This seems to work as I expect (please correct me if I'm wrong or if there's a better way). The trouble I'm having now is getting my Midje tests to pass. They pass correctly if I use the <code>doseq</code> version above. In my tests, I am using (provided .... ) to ensure that the correct calls are made, and I wish to use this to check the calls to my-function. Is it possible to do this? I'm finding it hard to find much information on pcalls.</p> <p>Thanks</p> <p>--------- Edit ---------</p> <p>I have contrived an example that demonstrates the failue.</p> <p>The implementation can be found <a href="https://gist.github.com/anonymous/2c9214af3bb49d44495d" rel="nofollow">here</a>, and the tests <a href="https://gist.github.com/anonymous/8dcf82068f5691b71309" rel="nofollow">here</a>. I have found that a single test runs fine, but multiple tests cause the following:</p> <blockquote> <p>FAIL at (pcalls_unit.clj:29) These calls were not made the right number of times: (my-func 2 2) [expected at least once, actually never called]</p> <p>FAIL "Test some pcalls 3" at (pcalls_unit.clj:26) Expected: nil Actual: java.util.concurrent.ExecutionException: java.lang.Error: You seem to have created a prerequisite for pcalls-test.pcalls/my-func that interferes with that function's use in Midje's own code. To fix, define a function of your own that uses my-func, then describe that function in a provided clause.</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload