Question: Problem: I have a list of users to delete. Not only the user himself is deleted, but also a significant amount of data associated with him. Some tables that are involved in deleting user information contain millions of records.
All internal processes are started asynchronously when deleted. And if, when deleting one user, there are no problems, and all processes in the background are successful (that is, the client does not expect a response), then if you run several of them, this takes all the server resources, which naturally negatively affects the work of the site as long as it goes removal.

```
for (let i = 0; i < users.length; i++) {
    const user = users[i];
    await this.removeInstance(user, removedBy);
}

```

**this.removeInstance** contains many other asynchronous operations.

What I want: start an asynchronous operation **this.removeInstance** at 3 minute intervals.
The speed of data deletion is not important to me, but according to my observations 1-2 minutes is exactly enough to "completely finish" with one user.

***Note:*** this.removeInstance return removed user, but I cannot use this, since a dozen processes are already running in the background to clear his information.

Thanks for any help!

Answer: 
Sorry to bother you, but a solution has been found.
[How do I add a delay in a JavaScript loop?](https://stackoverflow.com/questions/3583724/how-do-i-add-a-delay-in-a-javascript-loop/44476626)

Final:

```
public async removeBatchUsers(usersEmailsList: string[], removedBy: IIdentity) {
    const users: UserSchema[] = await User.find({userEmail: {$in: usersEmailsList}});

    const timer = ms => new Promise(res => setTimeout(res, ms));

    async function load (that) {
        for (let i = 0; i < users.length; i++) {
            const user = users[i];
            await that.removeInstance(user, removedBy);
            await timer(10000);
        }
    }

    load(this);
}

```

The solution above using Promise.allSettled is the most correct and safest. Tested it, in my case I had to additionally install the "promise.allsettled" library (23Kb)
If you're not too worried about about how long the whole process takes you can use a for..of loop with `await` to run `this.removeInstance` in series over the array:

```js
for (let user of users) {
  await this.removeInstance(user)
}

```

This will wait for each user to be removed before starting the next - you could then return a http 202 to the client to indicate the message is received and is being processed, perhaps also implementing a polling endpoint to check in on the status of the work.