Skip to content
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

Leave progress lightweight. Handle complicated situations with general message mechanism. #9

Open
coppercash opened this issue Oct 29, 2014 · 0 comments

Comments

@coppercash
Copy link

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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant