Search code examples
javascriptasynchronouspromiseasync-awaitsynchronous

Async-Await or Promises with JavaScript functions


I am building an application in Cordova using Firebase for the database.

I have been using promises to get information back from the database and it works great, but once I get that back I usually have a series of functions that I need to call to update everything.

For example,

  1. update local storage

  2. call variable from local storage

  3. reload page with updated storage information

I need to create/convert my JavaScript functions to be able to be called in succession.


Solution

  • What you are really asking is how to implement a function after a promise is done. If so, then making the function an Async function will do the trick.

    For information on async-await check out Async/await.