3

I have a following code (a part of function):

async addMarkers() {
    const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));

    function geoRequest(order) {
    }

    function setMarker(order) {
    }

    for (let i = 0; i < orders.length; i++) {
      if(orders[i].google_coords === '') {
        await timeout(1000);
        geoRequest(orders[i]);
      } else {
        setMarker(orders[i]);
      }
    }
  }

I need to execute some code only after for loop is completed. What should I do? Wrap addMarkers into Promise or something else? I tried to execute callback as parameter of addMarkers but it didn't help.

1 Answer 1

3

async functions return promises.

addMarkers().then(() => doSomething());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.