aleph

borkdude 2019-01-25T19:47:02.045Z

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

borkdude 2019-01-25T19:49:59.045500Z

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

kachayev 2019-01-27T15:54:25.046100Z

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)

borkdude 2019-01-27T16:07:20.046300Z

latest update where?

kachayev 2019-01-27T16:08:34.046600Z

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

borkdude 2019-01-27T16:12:17.046900Z

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

kachayev 2019-01-27T17:59:40.048800Z

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

borkdude 2019-01-27T18:44:41.049Z

gist would be cool 🙂

kachayev 2019-01-27T18:47:12.049400Z

Does this work for you?

borkdude 2019-01-27T18:49:20.049700Z

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.

kachayev 2019-01-27T19:12:56.050300Z

Yep. That’s correct!