I have 2 promises and i want to make something after both finish, but it doesn’t seem to run
I have this
console.log(loadFilesPromise);
console.log(getBucketAccessPromise);
console.log(111111111);
Promise.allSettled([getBucketAccessPromise, loadFilesPromise])
.then(results => {
console.log('FINISH ALL');
console.log(results);
this.$store.commit('setLoadingBucket', false);
})
.catch(error => {
console.log('asdasdasdasdasdasdasd');
reject(error)
});
console.log(2222222222);
This is the loadFilesPromise
loadFilesPromise = this.loadFiles()
#... this function is inside methods in Vue.js framework
async loadFiles() {
return api.getDir({
to: '',
})
.then(ret => {
console.log('Promise loadFilesPromise');
# more code
#... in another part
getDir(params) {
return new Promise((resolve, reject) => {
axios.post('getdir', {
dir: params.dir,
And this is the getBucketAccessPromise
let getBucketAccessPromise = new Promise((resolve, reject) => {
axios.post('getBucketAccess', {
username: '_self_'
})
.then(res => {
console.log('Promise 2');
# more code
and the output is
Promise {<pending>}
[[Prototype]]: Promisecatch: ƒ catch()constructor: .....
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: undefined # the undefined result is expected
Promise {<pending>}
[[Prototype]]: Promisecatch: ƒ catch()constructor: .....
[[PromiseState]]: "pending"
[[PromiseResult]]: undefined # the undefined result is expected
111111111
# the FINISH ALL log should be here
2222222222
Promise 1
Promise 2
This is confusing for me, Promise.allSettled should be wait for both promises, but instead this acts like it’s not there