Posts

Showing posts with the label async-await

React Native babelHelpers.asyncToGenerator is not a function (react-native 0.44.0)

I am new to react/react-native/babel world. I am trying to make async/await work. package.json { "name": "App", "version": "0.0.5", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.0.0-alpha.6", "react-native": "0.44.0", "react-native-fs": "^2.3.3" }, "devDependencies": { "babel-jest": "20.0.3", "babel-plugin-transform-async-to-generator": "^6.24.1", "babel-preset-react-native": "1.9.2", "babel-preset-stage-3": "^6.24.1", "jest": "20.0.3", "react-test-renderer": "16.0.0-alpha.6" }, "jest": { "preset": ...

When should I await my asyncs?

We're currently refactoring sections of our project to be async up and down, yay! Due to our different understanding, me and a colleague (let's call him Jim), have differing opinions about how our async/await code will execute, and which way to write it. Here is the example method Jim wrote: public async Task<HouseModel> GetHouseModel(Guid houseId) { House house = await _houseService.GetHouse(houseId); Task<IEnumerable<Furniture>> furniture = _furnitureService.GetFurnitureForHouse(house); Task<IEnumerable<Appliances>> appliances = _applianceService.GetAppliancesForHouse(house); return _houseModelFactory.MakeHouseModel(await furniture, await appliances); } And the example of how I would write it: public async Task<HouseModel> GetHouseModel(Guid houseId) { House house = await _houseService.GetHouse(houseId); IEnumerable<Furniture> furniture = await _furnitureService.GetFurnitureForHouse(house); IEnumerable<A...