-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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');