I am creating App integrating two systems. Therefore, I am using some requests and async functions. It's no problem to call async function in async function. However, I need to end somehow this chain and call async function in my main file where is App served from. Do you have any idea how to do it? Part of code looks like this
async function asyncFunctionINeedToCall() { await childAsyncFunction() } asyncFunctionINeedToCall()
To run an async function (coroutine) you have to call it using an Event Loop. Event Loops: You can think of Event Loop as functions to run asynchronous tasks and callbacks, perform network IO operations, and run subprocesses. Example 1: Event Loop example to run async Function to run a single async function: Python3.
In this article The current method calls an async method that returns a Task or a Task<TResult> and doesn't apply the Await operator to the result. 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.
Since the main scope is not async
, you will need to do an async anonymous function that calls your function and itself :
(async function() { await yourFunction(); })();
Or resolve the promise :
yourFunction().then(result => { // ... }).catch(error => { // if you have an error })
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