When chaining promises in Javascript, what happens if one function in the middle of the chain does not return anything, but still performs a async operation that needs to be completed before moving on?
Does the next 'then()' wait for the previous async function to resolve even though it is not passed any values?
EDIT: here's a application example:
connectDatabase()
.then(() => createTables())
.then(() => fillTables())
.then(() => selectTables)
.then(tables => showTables());
This code simply represents the creation of a SQLite database and some further operations to finally display the table values.
connectDatabase()
is a async function. Once the database is created, the function doesn't need to return anything since the database is stored in some global function (for use outside the promise chain). The next step doesn't need any arguments although it needs the database to be created to insert tables in it.
The createTables()
function creates some tables asynchronously and once it's done, it returns nothing and the next function can be called.
selectTables()
just uses the sql SELECT
command to store the table values in a variable and returns it to the next function.
showTables()
uses the table values that's passed on to it and displays on the screen.