0

I have a problem with calling a non-async function from the function method. Is there any way to do this?

Example:

async function myMethod()
{
  console.log('In async method');
  nonasyncmethod(); 
}

function nonasyncmethod()
{
  console.log('In non-async method');
}
Felix Kling
  • 756,363
  • 169
  • 1,062
  • 1,111
ANKIT SHARMA
  • 83
  • 1
  • 2
  • 10

1 Answers1

0

Yes, you can call both asynchronous and synchronous functions from within an async function - they do not have to be all asynchronous (of course the primary reason for having an async function is for asynchronous functions, but they work with synchronous functions as well):

async function myMethod() {
  console.log('In async method');
  nonasyncmethod();
}

function nonasyncmethod() {
  console.log('In non-async method');
}

myMethod();
Jack Bashford
  • 40,575
  • 10
  • 44
  • 74