Javascript
1module.exports.getNumbers = userId => new Promise((resolve, reject) => { 2 knex 3 .select('*') 4 .from('Users') 5 .where('user_id', userId) 6 .then(rows => { 7 console.log('1'); 8 let a = _.forEach(rows, (val, key) => { 9 return new Promise((resolve) => { 10 if (val.number === 1) { 11 console.log('2'); 12 s3Get('all', userId) 13 .then(arrKey => { 14 arrKeys = arrKey; 15 console.log('3'); 16 resolve(); 17 console.log('4'); 18 }); 19 } 20 }) 21 }, resolve()); 22 23 Promise.all(a).then(() => { 24 console.log('5'); 25 resolve('ok'); 26 }) 27 }) 28});
上記のコードを実行すると
console.log
が1 2 5 3 4
の順番で実行されてしまいます。
1 2 3 4 5
と順番に実行するにはどうしたらよいのでしょうか...。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。