Untitled
unknown
javascript
3 years ago
846 B
15
Indexable
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
}Editor is loading...