promises-aplus / progress-spec Goto Github PK
View Code? Open in Web Editor NEWDiscussion and drafts of a possible promise progress signalling spec
Discussion and drafts of a possible promise progress signalling spec
Some of the promises libraries now implement progress. The key thing that has yet to be decided upon is how we should deal with exceptions thrown in progress handdlers.
It has been broadly agreed upon that progress should be a single value (akin to fulfillment and rejection). We have also agreed that the third argument to then should be treated as the progress handler and should also controll propagation of progress.
I'd apreciate it if someone could fill in what the currently in use rules are regarding progress propagation.
We've been discussing a simpler idea for progress over at cujojs/when#264. The essence is that if you restrict progress values to being numbers between 0 and 1, combining them is easy. It rules out the use of arbitrary values for progress, but to me, that's a win.
I figured I'd cross-link here for potential discussion since it's a fairly different approach.
Do we need to support propagating more progress events than we recieve?
promiseA
.then(null, null, function (val, prop) { prop(0); prop(1);});
Maybe github has changed something but it does not link to the issues.
Sorry for jumping out suddenly. I have read a lot about your dicussion and got some thoughts in my head about presenting a reasonalbe value for progress.
My solution is to introduce a concept called fraction. The fraction indicates how complicated do you think the promise is compared to its directly parent promise. By default it's 0.5, which makes the following 2 statements are equal.
prms.then(undefined, undefined, function(progress){});
prms.progress(fcuntion(progress){}, 0.5)
Setting fraction to 0.5
may lead to '50%-for-many-50%-for-one' and 'fast-slow' issues (they are same in rough). So if you think the parent promise is much more complicated, 0.1
may be a more proper value for fraction.
If the library itself can handle the calculation for progress, maybe 'value-to-propagate' and 'feedback-for-callbacks-completion' can be saved to leave progress lightwieght. If there are more complicated situations need to be handled, general in-out message mechanism can be called. Things like 'partial' can be handled with something like this:
var prms = new Promise(function(resolver) {
var feedbackPrms = resolver.notify('partial', partialValue);
});
prms.listen('partial', function(value) {
// Do something with the partial result 'value'
return valueToPropagate;
});
What is on the inverse side is out-in message. I have seen other developers implemented cancel
pause
resume
, and there is no reason people won't ask for more. So may be the general message mechanism is a one-for-all solution. Like this:
var prms = new Promise(function(resolver) {
resolver.register('pause', function(){
// Do pause stuff
});
});
var pausePrms = prms.invoke('pause');
See #1
Progress handlers should be allowed to explicitly stop progress propagation. The trend in #1 seems to be toward allowing handlers to throw a duck-typed "stop propagation" error.
What should this error look like? One option is to follow builtin Error convention and have it be an Error whose .name == "<some specific name>"
, since we can't rely on instanceof
across implementations.
Two related questions:
My instinct is that we should only support throwing the stop propagation error.
#5 is concluding with an updated draft (https://gist.github.com/4400252) and an implementation. We now need a list of progress use cases and see if the behavior that flows from the spec is as expected.
This has lots of holes in it, I'm putting it here though, because I'm hoping that we'll start to see where the holes are and fill some of them in a little.
This proposal specifies how progress is triggered and propagated in a PromisesA+ promise library.
then
methodThe then method is the same as that specified in the promises-spec except that it also takes a third argument. We'll call that third argument the onProgress
.
onProgress
onProgress
is not a function
onProgress
is a function
onProgress
is called with the ProgressValue
as the first argument.onProgress
throws an exception with a .name
property equal to 'StopProgressPropagation'
then the error is silenced and progress is not propagated. In all other cases, the result of the function is used as the progress value to propagate.onProgress
is never called once a promise has already been fulfilled or rejected.progress
methodThe resolver has a .progress(value)
method. This triggers all the onProgress
methods. It returns a promise which is fulfilled with undefined
once all progress methods are complete or is rejected with the first (non-StopProgressPropagation) exception thrown by the handlers, if any.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.