LoginSignup
0
1

More than 5 years have passed since last update.

Promiseで並列処理をつなぐ

Posted at

メモ。近いうちもっと分かりやすいPromise記事書こう。

qiita.js
    function randomInt(min, max) { 
        return Math.floor(Math.random() * (max - min) + min);
    }
    function timerPromisefy(index) {
        return new Promise(function (resolve) {
            const interval = randomInt(100, 1000);
            setTimeout(function () {
                console.log('index: ' + index + ' interval: ' + interval);
                resolve();
            }, interval);
        });
    }
    const startDate = Date.now();
    Promise.resolve()
    .then(function() {
        return Promise.all([
            timerPromisefy(1),
            timerPromisefy(1),
            timerPromisefy(1),
            timerPromisefy(1)
        ]);
    }).then(function() {
        return Promise.all([
            timerPromisefy(2),
            timerPromisefy(2)
        ]);
    });
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1