Untitled
unknown
javascript
2 years ago
846 B
6
Indexable
Never
const button = document.querySelector('button') function listDirecotriesAsync(path = '') { return new Promise((resolve, reject) => { listDirectory( path, (response) => { resolve(response) }, (error) => { reject(error) } }) }) } // asynchronous way async function mainAsync () { disableButton() const requests = ['pathA', 'pathB', 'pathC'].map(listDirectoriesAsync) await Promise.all(requests) enableButton() } // synchronous way function main () { disableButton() const requests = ['pathA', 'pathB', 'pathC'].map(listDirectoriesAsync) await Promise.all(requests).then(enableButton) } function disableButton() { button.disabled = true } function enableButton() { button.disabled = false }