Git Product home page Git Product logo

Comments (6)

leonoel avatar leonoel commented on July 3, 2024 1

@den1k more details here #51

from missionary.

den1k avatar den1k commented on July 3, 2024

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.

den1k avatar den1k commented on July 3, 2024

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.

leonoel avatar leonoel commented on July 3, 2024

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.

den1k avatar den1k commented on July 3, 2024

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.

dustingetz avatar dustingetz commented on July 3, 2024

Hey can you switch to the slack for support please, this emails 22 people

from missionary.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.