what’s the manifold.deferred equivalent of future-cancel?
I’d really like to cancel the future that’s associated with the deferred
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)
latest update where?
https://github.com/ztellman/manifold/issues/166 (I thought that was a PR, but that was an issue, sorry for confusion)
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 READMEIt’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
gist would be cool 🙂
https://gist.github.com/kachayev/a279a728a4a73f16aabbebaedb94ea95
Does this work for you?
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.
Yep. That’s correct!