Fork me on GitHub
#aleph
<
2019-01-25
>
borkdude19:01:02

what’s the manifold.deferred equivalent of future-cancel?

borkdude19:01:59

I’d really like to cancel the future that’s associated with the deferred

kachayev15:01:25

I think the idiomatic way to cancel something in Manifold is to resolve appropriate deferred with an error (this would short-circuit all chained callbacks). If you also want to cancel some long running computation: give it deferred to put the result into and make it check periodically if deferred is still in not-realized state (see latest update for d/loop for example)

borkdude16:01:20

latest update where?

kachayev16:01:34

https://github.com/ztellman/manifold/issues/166 (I thought that was a PR, but that was an issue, sorry for confusion)

borkdude16:01:17

so currently it’s not well supported? say I have a future:

(def f (future
         (println "1")
         (Thread/sleep 10000)
         (when-not (Thread/interrupted)
           (println "2")
           (Thread/sleep 10000)
           (when-not (Thread/interrupted)
             ...))))
             
(do (Thread/sleep 5000) (future-cancel f))
  ;; 2 is never printed
How is this translated to manifold? I think it would be worth having this example in the README

kachayev17:01:40

It’s not supported for deferred/loop right now, but the approach described in the issue I’ve mention is what you’re looking for. Let me put a gist for you

borkdude18:01:41

gist would be cool 🙂

kachayev18:01:12

Does this work for you?

borkdude18:01:20

I think it’s clear now. So instead of checking for (Thread/interrupted), I check for (d/realized? …), because when I “cancel” it (putting an error value in it), it’s realized. Thanks.

kachayev19:01:56

Yep. That’s correct!