/** * Example of top-level await in a Node for Max script, loaded as * an ECMAScript module. */ import * as Max from 'max-api'; // Simple sleep utility function to simulate an asynchronous task const sleep = (time) => new Promise(resolve => setTimeout(resolve, time)); let countMax = 5; let waitMs = 100; for (let i = 1; i < countMax; i++) { await sleep(waitMs); await Max.post(`Waited ${waitMs * i} milliseconds`); } Max.addHandler("echo", async (msg) => { await Max.outlet(msg); });