The javascript code is in itself correct, and you can include it direcly in the EXEC_SCRIPT function. For example:
EXEC_SCRIPT 'async function main() {await new Promise(resolve => setTimeout(resolve, 2000));} main();'
(I shortened the code a bit, at the expense of readability).
However, I tested this and it does not work. This is because AwareIM executes the code asynchronously, in other words it starts the execution of the javascript code on the client but doesn’t wait for the script to finish (after the 2 second delay). So it does not actually delay the server (apart from the short time that it takes to send the javascript call to the client).
In principle it would be technically possible to have a java function (not javascript) executed on the server, but this is rather complicated so I wouldn’t recommend that.
A better approach is probably to use the scheduling function. The scheduler can call a process at regular intervals, which process calls the REST API for only a limited number of records and then terminates, and continues at the next call by the scheduler. You need to implement a counter that keeps track of the records that are being processed (which I think could be stored in the session object, haven’t tested that). The big advantage of this approach is that it doesn’t freeze the server, it remains responsive and available to do other stuff while the API calls are being made in the background. In the case that the REST API calls are being started by a user, it’s probably useful to have the process send a notification after all records have been processed, to inform the user.