u/rster2002in r/node • Recommends
On “Retry loop with a pause between attempts”
Async await is only for when working with promises. setTimeout does not return a promise, so async await would not work. To get it to work you would have to create something like this:
```javascript
const wait = delay => {
return new Promise (res => {
setTimeout(() {
res();
}, delay);
});
}
// Your function
await wait(2000);
```
Also, you'll need to make `waitForDevice` return a promise.
```javascript
const wait = delay => {
return new Promise(res => {
setTimeout(() => {
res();
}, delay);
});
}
const waitForDevice = (device) => {
return new Promise(async (res, rej) => {
// A promise exposes two functions: respond and reject
// If you then performed…