-
Notifications
You must be signed in to change notification settings - Fork 5
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
Draft A #2
Comments
Is it Does the Does
This is strangely worded. I assume you mean to say that the resolver that's behind the promise we invoked
What does this event mechanism look like? How are the handlers allowed to affect the resolver? E.g. resolver.onCancelled = function(reason, data, resolver){}
resolver.onCancelled = function(rejectionReason, resolver){}
resolver.on("cancelled", function(reason, data){} etc. |
Do we need both |
I don't mind which, I come from the UK but (as much as I dislike it) we should probably use the US spelling, whatever that is. I think we can drop
Yes, that's what I mean.
I was to be honest thinking something more like: resolver.on('cancelled', function () {
} It shouldn't actually affect the resolver in any way at all, it's only there to cancel the underlying operation. The resolver/promise combo handle behaving correctly when cancelled, but they can't stop the now un-necessary work from continuing to be done. By terminating connections to web-servers, for example, lots of wasted resources might be freed up. The advantage of having reason and data is that we can turn the result into an exception with reason as the message, but if data is used it could be an object and that wouldn't work as well. It's a good point though, and the solution presented here is probably sub-optimal. |
Ha, that's the response I got in London when talking about Dojo's API. I picked
Oh! You mean that the upstream promise transitions into a What would happen to other promises that branched of the upstream one? I presume they also get silently canceled, which means they won't realize and can't clean up any associated state. You could reject all promises but then Regarding using a
In my implementations I like the generic |
Hmmm, maybe we do need to mandate some kind of reference counting so we don't get the situation described. Perhaps each call to Yeh, I just think that because it might end up getting logged like an exception sometimes, we should make sure it's possible to set the message to something helpful. |
I assume you mean having branched promise chains not being affected if one of them gets canceled? I may experiment with reference counting tomorrow. What would happen if two branches are canceled? The first cancelation won't immediately reach the resolver, but when the ref count drops to 0 at least one of them has to. I suppose the first could win?
True, but that's immediately relevant for control flow purposes. Perhaps |
Yes that's what I meant. I don't think we should provide any info except that it's been cancelled to the resolver, so it doesn't matter which one wins. Message and data should be sufficient. You can always set data to be a string. |
I've added an updated draft at https://gist.github.com/4399269, not sure whether this should already be Draft B. It covers a few edge cases found whilst doing the implementation, see https://github.com/novemberborn/legendary/tree/cancelation. Still need to write some tests… |
Is there a way to do this without a public I dislike
This extra cancelled state seems bad. When directly cancelled, you just transitioned to the rejected state. Am I unable to observe that rejection, since now we're no longer in the rejected state? What was the point of rejecting then?
I don't think I like this mechanism, but I admit I can't think of much better. Maybe it becomes
Ick, I don't like this. We should have specified it to be
I am very leery of this kind of behavior that relies on a promise knowing who depends on it. It defeats programs that set up promise dependency chains after some time, and thus defeats using promises as first-class objects. See related discussions in the unhandled-rejections repo. Furthermore, none of this seems to address the communications channel issue. Promises need to be by-default uncancellable; that is, the |
The way we've defined var A = fulfilled();
var B = pending().promise;
var C = A.then(function(){
return B;
});
var D = B.then(function(){
…
});
C.cancel(); Here canceling
I've found it useful, especially since the rejection travels down the promise chain.
Oh that's good! But then should you be able to override the
With the implementation I did at this point, the resolver is only canceled if cancelation was propagated from its only promise. Therefore there is no rejection to observe. However if you call
I like that, and it's closer to what e.g. Dojo has done up to now, with
Agreed. And I suppose most implementations will invoke the callback that way.
What we're trying to avoid is having cancelation on one promise affect other promises that stem from the same resolver. The way to do that is to only cancel the resolver when its last promise is canceled. If more promises are derived at a later point those would be rejected because the resolver was rejected. Alternatively cancelation could be advisory only at the resolver level, but I'm not sure whether that would solve the problem.
I like that. However if Promises/A+ defines a promise as having a (I'd prefer it to be a no-op though, testing for |
Very early draft of Cancellation Spec, I think it's probably too early to do a great job, but hopefully this will create some interesting talking points.
Cancellation/A+
This proposal specifies how cancellation is triggered, handled and propagated in a Promises/A+ promise library.
Terminology
In addition to the terminology from promises/A+ we use the following:
Requirements
The
CancellationException
When a promise is directly cancelled it is rejected with a CancellationException. A CancellationException MUST obey the following points:
cancellationException instanceof Error === true
).name = 'OperationCancelled'
.cancelled = true
The
cancel
MethodWhen the
cancel
method is called on a promise it is directly cancelled. The cancel method accepts two arguments.CancellationException
reason
anddata
are optionalreason
is not a string it SHOULD default to'Operation Cancelled'
.data
isundefined
it SHOULD be ignored.reason
is a string it is used as themessage
property in theCancellationException
data
is notundefined
it is set as thedata
property of theCancellationException
this.propagateCancel()
and return the result.The
propagateCancel
methodThe propagateCancel method is intended only to be called by this and other promises, it is not for external use.
When propagateCancel is called, the promise transitions into an extra
cancelled
state. This does not trigger any events. It does however mean that the promise can never be resolved (i.e. it never leaves the cancelled state)..propagateCancel()
on the promise it is waiting for.In most cases it should call
.propagateCancel()
on the promise it's waiting for. The exception is if the promise has been in some way 'forked', when it may choose not to in an implimentation specific way.The
cancelled
EventWhen a promise is cancelled ( directly or indirectly) the resolver for that promise must emit a
'cancel'
event.The text was updated successfully, but these errors were encountered: