Fork me on GitHub
#missionary
<
2022-04-21
>
adamfrey17:04:19

Is it expected that I should be able to support cancellation with a concurrent forking ap block via m/?= ? For instance:

(time (m/? (m/timeout (->> (m/ap
                            (let [x (m/?> (m/seed (range 2000000)))]
                              (m/? (m/sleep 1))
                              x))
                           (m/reduce (fn [_ x]
                                       (Math/sqrt x))
                                     0))
                      2
                      ::timeout)))
returns ::timeout in 2 milliseconds but:
(time (m/? (m/timeout (->> (m/ap
                            (let [x (m/?= (m/seed (range 2000000)))]
                              (m/? (m/sleep 1))
                              x))
                           (m/reduce (fn [_ x]
                                       (Math/sqrt x))
                                     0))
                      2
                      ::timeout)))
returns 1414.19... in 2500 milliseconds

leonoel20:04:28

In the first example the cost of the machinery is very low, because it only spawns a couple of child branches, one at a time. The logical duration of the process is 2000000 ms therefore it times out. In the second example we spawn two million child branches and make as many requests to the scheduler, this is significant work, I guess that's what the 2500 ms are spent for, there's no way to make that cancellable because it's not userland. The logical duration of the process is 1 ms, therefore it doesn't time out.

👍 3