This is what I'm trying do in React-Native. Async functions are making calls to firebase.
async functionOne() {
asyncStuffHappens
}
functionTwo() {
this.functionOne();
}
this.functionOne();
is undefined. I'm not sure how to call an async function from another function.
Just treat async call as promise and attach . then to it: async function wait() { await new Promise(resolve => setTimeout(resolve, 1000)); return 10; } function f() { // shows 10 after 1 second wait().
You can not use the await keyword in a regular, non-async function. JavaScript engine will throw a syntax error if you try doing so.
async and await Inside an async function, you can use the await keyword before a call to a function that returns a promise. This makes the code wait at that point until the promise is settled, at which point the fulfilled value of the promise is treated as a return value, or the rejected value is thrown.
The call to the async method starts an asynchronous task. However, because no Await operator is applied, the program continues without waiting for the task to complete. In most cases, that behavior isn't expected.
Like this:
async functionOne() {
asyncStuffHappens
}
functionTwo() {
(async () => {
await this.functionOne();
})();
}
This is called an IIFE (Immediately-invoked function expression). It's a function executed right after it's created
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With