-
Notifications
You must be signed in to change notification settings - Fork 25.1k
AsyncGenerator doesn't exist / work #27432
Description
It seems that AsyncGenerator is not supported in RN? Usage of ES6 async generator is resulting in errors when the same code operates as expected in a standard ES6 React web application.
I'm on a pretty recent RN and am experiencing a strange issue I did not expect. Could this have to do with version of babel or metro packages?
React Native version:
System:
OS: macOS 10.15.1
CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Memory: 381.77 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.16.2 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.10.3 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
Android SDK:
API Levels: 23, 24, 27, 28
Build Tools: 23.0.3, 26.0.1, 28.0.3, 29.0.2
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.6010548
Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
npmGlobalPackages:
react-native-cli: 2.0.1
Possbily relevant dependencies
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"jest": "^24.9.0",
"babel-jest": "^24.9.0",
"jetifier": "^1.6.4",
"metro-react-native-babel-preset": "^0.56.0"
Steps To Reproduce
- Execute this code in RN app:
async function* asyncGen() {
yield 'whatever';
}
console.log(asyncGen());
for await (const res of asyncGen())
console.log('result', res);- Observe results
When run on a web application, the console.log will show AsyncGenerator {...} and usage of the object in a loop like for await (const result of asyncGen()) works as expected. However, when using the same code in my RN app, the log statement shows:
AsyncIterator {_invoke: ƒ}_invoke: ƒ enqueue(method, arg)arguments: (...)caller: (...)length: 2name: "enqueue"prototype: {constructor: ƒ}__proto__: ƒ ()[[FunctionLocation]]: runtime.js:167[[Scopes]]: Scopes[3]__proto__: next: ƒ (arg)return: ƒ (arg)throw: ƒ (arg)Symbol(Symbol.asyncIterator): ƒ ()constructor: ƒ AsyncIterator(generator)__proto__: ObjectAnd usage in the same form of for await (... of ..) yields:
TypeError: _iterator[(intermediate value)(intermediate value)(intermediate value)] is not a function
TypeError: _iterator[(intermediate value)(intermediate value)(intermediate value)] is not a function
at WorkoutHistory.fetchSets$ (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:163566:234)
at tryCatch (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:23518:19)
at Generator.invoke [as _invoke] (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:23693:24)
at Generator.prototype.<computed> [as next] (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:23561:23)
at tryCatch (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:23518:19)
at invoke (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:23594:22)
at blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:23624:13
at tryCallTwo (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:24829:7)
at doResolve (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:24993:15)
at new Promise (blob:http://localhost:8081/8ee39d52-49af-4c3e-a8a7-b3d585ce1223:24852:5)
[![error messages][1]][1]
Pretty unclear what exactly the issue is, some insight as to whether it's a me problem or a bug would be appreciated. Thanks!