Search code examples
javascriptasync-awaites6-promise

Execute two functions without .then()


Currently I have this code:

client.clearStore()
  .then(() => someFunction())
  .catch(e => logger.error('error', e));

It works okay but I have a problem on testing with .then(), so I wondered if there is an another way to execute both client.clearStore() and someFunction() but having finished client.clearStore() that returns a promise.


Solution

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function

    (async () => {
      try {
        const someFunction = await client.clearStore();
    
        someFunction();
      } catch (e) {
        logger.error('error', e);
      }
    })();