What happens with $q.all() when some calls work and others fail?

Alan2 :

What happens with $q.all() when some calls work and others fail?

I have the following code:

    var entityIdColumn = $scope.entityType.toLowerCase() + 'Id';
    var requests = $scope.grid.data
      .filter(function (rowData, i) {
          return !angular.equals(rowData, $scope.grid.backup[i]);
      })
      .map(function (rowData, i) {
          var entityId = rowData[entityIdColumn];
          return $http.put('/api/' + $scope.entityType + '/' + entityId, rowData);
      });
    $q.all(requests).then(function (allResponses) {
        //if all the requests succeeded, this will be called, and $q.all will get an
        //array of all their responses.
        console.log(allResponses[0].data);
    }, function (error) {
        //This will be called if $q.all finds any of the requests erroring.
        var abc = error;
        var def = 99;
    });

When all of the $http calls work then the allResponses array is filled with data.

When one fails the it's my understanding that the second function will be called and the error variable given details.

However can someone help explain to me what happens if some of the responses work and others fail?

Chandermani :

I believe since the promise library is based on Q implementation, as soon as the first promise gets rejected, the reject callback is called with the error. It does not wait for other promises to resolved. See documentation of Q https://github.com/kriskowal/q. For Q.all this is what is mentioned

The all function returns a promise for an array of values. When this promise is fulfilled, the array contains the fulfillment values of the original promises, in the same order as those promises. If one of the given promises is rejected, the returned promise is immediately rejected, not waiting for the rest of the batch.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What happens when all the datanodes fail in hadoop?

From Dev

What to do when a button click work for some datasets and not for others?

From Dev

What happens when a thread that calls Condvar::wait(condvar, some_mutex) is spuriously woken?

From Dev

What happens when a destructor calls an abstract function

From Dev

What happens when a thread calls longjmp() in c

From Dev

What happens when running (int *)"some string"

From Dev

Why do some function calls fail to work without a type application?

From Dev

What happens on write() fail?

From Dev

What exactly happens when you fail to use unbind()?

From Dev

What happens when update_all fails?

From Dev

Make $q.all fail silently when one promise is rejected

From Dev

When finding the prime factors of a number some numbers work but others dont

From Dev

What exacly happens when a class constructor calls a setter

From

What happens when a constructor function calls itself in VS2013?

From Dev

What happens when a UDP socket calls a TCP socket

From Dev

What exactly happens when one calls a 'spawn' function?

From Dev

How to have make fail on some warnings but not others

From Dev

Conversion String to Float fail for some number but not others

From Java

When an Thread.interrupt() is called on some thread, what happens?

From Dev

What happens when I would leave some breakpoints in my code?

From Dev

What happens when a validator does not see +2/3 precommits, while others do?

From Dev

AllowAnyMethod works for some API calls but not for others

From Java

Making Maven run all tests, even when some fail

From Dev

how does itemgetter work? what happens when we initialise it to key

From Dev

What happens to a Kafka consumer group when all consumers are removed

From Dev

what happens when all bits in a hard-disk are set to one?

From Dev

What happens when you lose all references to a Python thread?

From Dev

Heroku: What happens when my Redis connection are all used?

From Dev

Why does this C++ program work in some compilers but not others? What is the major difference between c++ compilers?

Related Related

  1. 1

    What happens when all the datanodes fail in hadoop?

  2. 2

    What to do when a button click work for some datasets and not for others?

  3. 3

    What happens when a thread that calls Condvar::wait(condvar, some_mutex) is spuriously woken?

  4. 4

    What happens when a destructor calls an abstract function

  5. 5

    What happens when a thread calls longjmp() in c

  6. 6

    What happens when running (int *)"some string"

  7. 7

    Why do some function calls fail to work without a type application?

  8. 8

    What happens on write() fail?

  9. 9

    What exactly happens when you fail to use unbind()?

  10. 10

    What happens when update_all fails?

  11. 11

    Make $q.all fail silently when one promise is rejected

  12. 12

    When finding the prime factors of a number some numbers work but others dont

  13. 13

    What exacly happens when a class constructor calls a setter

  14. 14

    What happens when a constructor function calls itself in VS2013?

  15. 15

    What happens when a UDP socket calls a TCP socket

  16. 16

    What exactly happens when one calls a 'spawn' function?

  17. 17

    How to have make fail on some warnings but not others

  18. 18

    Conversion String to Float fail for some number but not others

  19. 19

    When an Thread.interrupt() is called on some thread, what happens?

  20. 20

    What happens when I would leave some breakpoints in my code?

  21. 21

    What happens when a validator does not see +2/3 precommits, while others do?

  22. 22

    AllowAnyMethod works for some API calls but not for others

  23. 23

    Making Maven run all tests, even when some fail

  24. 24

    how does itemgetter work? what happens when we initialise it to key

  25. 25

    What happens to a Kafka consumer group when all consumers are removed

  26. 26

    what happens when all bits in a hard-disk are set to one?

  27. 27

    What happens when you lose all references to a Python thread?

  28. 28

    Heroku: What happens when my Redis connection are all used?

  29. 29

    Why does this C++ program work in some compilers but not others? What is the major difference between c++ compilers?

HotTag

Archive