The issue
I'm curious if it would be possible to consume a generator-function in async/await context within modern ES2017. (The application is a React-native-application)
This is my code where I want to call the generator function:
class ProductViewComponent extends Component {
async componentDidMount() {
const result = await loadProduct(...)
console.log(result) // Gives: *Generator* and not the final result
}
}
The function loadProduct()
was imported from another file and is defined as follows:
export function * loadProduct(id) {
let product = yield select(productByIdSelector(id));
if(!product) {
// ... yield this
// ... yield that
// ... finally:
product = yield call(loadProductFromWeb, id)
}
return product;
}
The concrete question:
As far as I know I can use await
to await results from Promises. How can I use generator functions in this context?