Code Monkey home page Code Monkey logo

progress-spec's People

Contributors

briancavalier avatar domenic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

qdigital

progress-spec's Issues

Background

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.

A simpler notion of progress

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.

Doubling up

Do we need to support propagating more progress events than we recieve?

promiseA
  .then(null, null, function (val, prop) { prop(0); prop(1);});

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

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');

Stopping progress propagation

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:

  1. Would it be better to return such an error rather than throw it?
  2. Would it be ok to allow returning such an error in addition to throwing it?

My instinct is that we should only support throwing the stop propagation error.

Draft A

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.

Progress/A+

This proposal specifies how progress is triggered and propagated in a PromisesA+ promise library.

Requirements

The then method

The 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.

The onProgress

  1. If the onProgress is not a function
    1. It is ignored
  2. If the onProgress is a function
    1. When progress is emitted, the onProgress is called with the ProgressValue as the first argument.
    2. If the 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.
    3. onProgress is never called once a promise has already been fulfilled or rejected.

The progress method

The 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.