Comments (6)
from missionary.
Fixed!
(time
(let [delays [{:id 1
:delay 1000}
{:id 2
:delay 2000}
{:id 1
:delay 500}
{:id 1
:delay 200}]]
(m/?
(->>
(m/ap
(let [[k vs] (m/?> ##Inf (m/group-by :id (m/seed delays)))
m (m/?< vs)]
(try
(m/!) ; <---- fixed
(m/?
(m/via m/blk (Thread/sleep (:delay m)) (assoc m :slept true)))
(catch missionary.Cancelled c
(println :cancelled m)
(m/amb)))))
(m/reduce
(fn [out v]
(println v)
(conj out v))
[])))))
from missionary.
Reopening as Cancelled still does not throw when run downstream from m/observe
(declare put)
(def c
(let [observe-flow (m/observe (fn [!]
(defn put [x]
(! x))
#(do)))
task (->>
(m/ap
(let [[k vs] (m/?> ##Inf (m/group-by :id observe-flow))
m (m/?< vs)]
(try
(m/!) ; <---- fixed
(m/?
(m/via m/blk (Thread/sleep (:delay m)) (assoc m :slept true)))
(catch missionary.Cancelled c
(println :cancelled m)
(m/amb))
(catch Throwable t
(println :throwing-instead-of-cancelling)
(m/amb)
))))
(m/reduce
(fn [out v]
(println v)
(conj out v))
[]))
cancel (task (fn [s] (println :success s))
(fn [f] (println :fail f)))]
cancel
))
(put {:id 1
:delay 200})
=> nil
{:id 1, :delay 200, :slept true}
(do (put {:id 1
:delay 200})
(put {:id 1
:delay 500}))
:throwing-instead-of-cancelling
=> nil
{:id 1, :delay 500, :slept true}
from missionary.
On cancellation, m/via
interrupts the thread. The final result depends how the body reacts to thread interruption, in this case Thread/sleep
will stop and throw InterruptedException
. The right fix is to catch InterruptedException
.
In the first example, m/!
works by accident because the switch happens immediately, before the sleep even starts.
from missionary.
hmm, the issue is that various exceptions can be thrown as arbitrary sandboxed code is run by the user. Is there any other way to detect Cancellation by m/?<
?
from missionary.
Hey can you switch to the slack for support please, this emails 22 people
from missionary.
Related Issues (20)
- Doc strings with empty or malformed code blocks
- Consider fairness for `sem`, `dfv`, `mbx`, `rdv`
- discourage unbounded queues - `mbx`, `blk`
- ClojureDart and Flutter HOT 2
- Cannot set properties of undefined (setting 'parent') HOT 2
- Cannot read properties of null (reading 'parallelism')
- nullpointerexception with subscribe HOT 6
- `m/sleep` does not terminate after exception HOT 1
- task succeeds on cancel when task body is wrapped in a try/catch HOT 10
- `m/mbx` on post can return non-nil value, the docs say otherwise
- `ap` bug
- Cancel in example for basic walkthrough doesn't work HOT 3
- watch can discard latest value
- Hello task example prints only Hello with Clojure repl HOT 4
- generalize `signal` to any semigroup HOT 1
- `observe` - on JVM, consider parking the caller thread instead of throwing when pipeline is busy HOT 2
- make `ap` switch consistent with `cp` HOT 1
- `stream` double subscriptions - document correct pattern + investigate bug
- cycles in continuous time - distill the essence of problem, find correct patterns and provide helpers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from missionary.