question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native 0.63 introduces Promise.allSettled but don't work

See original GitHub issue

React Native 0.63 introduces Promise.allSettled but don’t work.

Description

Until version 0.61 we have used the Promise.allSettled polyfill, but in React Native 63 it stopped working because the Promise.allSettled is a valid function and polyfill is ignored.

However, the native Promise.allSettled don’t work as expected.

React Native version:

System:
    OS: macOS 10.15.7
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 136.63 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.19.0/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.1, DriverKit 19.0, macOS 10.15, tvOS 14.0, watchOS 7.0
    Android SDK:
      API Levels: 23, 26, 27, 28, 29
      Build Tools: 23.0.1, 23.0.3, 24.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.0, 29.0.2, 30.0.1
      System Images: android-29 | Google Play Intel x86 Atom
      Android NDK: 20.1.5948944
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 12.1/12A7403 - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_181 - /usr/bin/javac
    Python: 3.8.2 - /Users/douglas/.pyenv/shims/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1 
    react-native: 0.63.3 => 0.63.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Run any code like that:
const successReq = (wait) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve(new Date());
    }, wait);
  });
};

const errorReq = (wait) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      reject(new Date());
    }, wait);
  });
};

const makeRequest = async () => {
  const result = await allSettled([
    successReq(500),
    successReq(1000),
    errorReq(600),
    successReq(1500)
  ]);

  console.log({ result });
};

makeRequest();
  1. See the buggy result in console:
{
    "result": [
        {
            "_bitField": 33554432,
            "_settledValueField": 2020-10-23T18: 43: 47.045Z
        },
        {
            "_bitField": 33554432,
            "_settledValueField": 2020-10-23T18: 43: 47.543Z
        },
        {
            "_bitField": 16777216,
            "_settledValueField": 2020-10-23T18: 43: 47.143Z
        },
        {
            "_bitField": 33554432,
            "_settledValueField": 2020-10-23T18: 43: 48.219Z
        }
    ]
}

Expected Results


{
  "result": [
    {
      "status": "fulfilled",
      "value": "2020-10-23T18:52:51.836Z"
    },
    {
      "status": "fulfilled",
      "value": "2020-10-23T18:52:52.336Z"
    },
    {
      "status": "rejected",
      "reason": "2020-10-23T18:52:51.936Z"
    },
    {
      "status": "fulfilled",
      "value": "2020-10-23T18:52:52.837Z"
    }
  ]
} 

Snack, code example, screenshot, or link to a repository:

I don’t think that is necessary.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
ahartzogcommented, May 14, 2021

Promise.allSettled is undefined in React Native 0.64.1 for me. Using Hermes for both iOS and Android now.

5reactions
pktippacommented, Jul 9, 2021

you can implement allSettled by yourself.

const allSettled = (promises) => {
  return Promise.all(promises.map(promise => promise
      .then(value => ({ state: 'fulfilled', value }))
      .catch(reason => ({ state: 'rejected', reason }))
  ));
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise allSettled is not a function - Stack Overflow
I planned updating some Promise.all to Promise.allSettled in my React Native - Expo Project but the function does not Exist. i checked all ......
Read more >
Mastering Promise.allSettled in React - Medium
allSettled comes in to play. Promise.allSettled will wait for every promise in the array, regardless of whether it rejects and will call our...
Read more >
@react-native/polyfills | Yarn - Package Manager
React Native brings React's declarative UI framework to iOS and Android. With React Native, you use native UI controls and have full access...
Read more >
Solve* all your problems with Promise.allSettled() - Mike Bifulco
react. Promise.allSettled() is a new API coming to the JavaScript / ES6 ... and returns an array with the responses from each promise:....
Read more >
What's wrong with Promise.allSettled() and Promise.any()
all/Promise.race which reject with just an Error instance. How will JavaScript look like if every new Promise API method will introduce new way ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found