1
2
3
async function sleep(millis) {
return new Promise(resolve => setTimeout(() => res(42), millis))
}

Here a better (by meaning not by look) name for resolve would be setPromiseStatusToResolvedAndSetValueTo.
Note that the function passed into the new Promise constructor gets immediately executed synchronously. The special thing about Promise is when it gets “handled”, not when it gets created.