-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancellation API as a first-class citizen? #167
Comments
The short-circuiting also allows us to do something like this: (let [r-a (query-a)
r-b (query-b)]
(d/connect r-a r-b)
r-b) This means that |
I've been thinking about I think they don't use
Regarding "cancellable"
I think those exhaust the list of potential use cases which are not covered by short-circuiting of chained listeners. But maybe I'm missing something. |
As I mentioned in #166 current implementation doesn't cover even chain use cases, for example, nested chains. |
@prepor This one? (->
(deferred/chain
(deferred/chain
(deferred/future (Thread/sleep 2000))
(fn [_]
(prn "----FINISH")
:finished))
(fn [_] :finished))
(deferred/timeout! 1000)
(deref)) In this example printing of (->
(d/chain
(d/chain
(d/future (Thread/sleep 2000))
(fn [_]
(prn "----FINISH")
:finished))
(fn [_] :finished))
(d/timeout! 1000)
(d/chain (fn [_] (prn "after timeout")))
(deref))
|
The idiomatic way to "cancel" deferred in Manifold is to put an error value in order to short-circuit all chained listeners. Recently we had quite a few questions around this specific functionality... So, I wonder if it's better to have a public API in place to deal with cancellation? E.g.
We also need to document that cancellation of
d/future
ord/future-with
does not interrupt the underlying thread (which would be expected because offuture-cancel
semantic from Clojure core).More advanced thins in terms of cancellations:
d/zip
andd/alt
that propagate cancellation to underlying deferreds.It might be simple for 2 mentioned functions... but maybe we can think of a more general approach/solution where we can manually specify (or automatically derive?) a graph of connections between different deferred to use it to propagate
CancelledExceptions
properly?Keeping in mind previous item... should we treat
TimeoutException
as a cancellation?Self-referencial
cancelled?
checker ford/future
. That's arguable, but often times I need this:I'm not sure about this specific feature as it undercovers underlying mechanics to some extent. It's still doable by introducing a separate deferred in a lexical scope, but this approach might not be obvious for beginners. So, at least it should be well-documented.
@ztellman WDYT?
The text was updated successfully, but these errors were encountered: