0

Let's say I have a class that has two functions, first one is basic one which is called somewhere from the instance and the second one is asynchronous, which is called from the first one.

When I try to implement this logic in node, I always get error SyntaxError: Unexpected reserved word and pointing on line with await inside the if statement.

Has anyone encountered something like that before, or is there a walkaround? Thanks

class Class1 {

  init(){
    
    if( await isDataReceived()){
      doSomething();
    }
  }

  async isDataReceived() {
    return (Object.keys(JSON.parse(await request('google.com')).length != 0))
  }

}
TheShalty
  • 144
  • 7

1 Answers1

0

init() needs to be an async function