How to make function wait for all queries to execute before triggering again?

If I'm understanding your situation correctly you might be able to just copy that code directly as your query (the red lines are because it's done in an environment that doesn't have the proper references):

If you return a promise from a JS query it will run until that promise is either resolved or rejected. Since every time you run .trigger on a query it actually returns a promise, we can call .map on your table to create an array of the individual query promises. We then return Promise.all(insertQueries) since that is itself a promise that completes when all the Insert_Assessments_Airtable queries have completed.