Skip to content

Instantly share code, notes, and snippets.

@Namchee
Created April 28, 2021 06:57
Show Gist options
  • Select an option

  • Save Namchee/a1b00d34d1663e016163b96e578ad521 to your computer and use it in GitHub Desktop.

Select an option

Save Namchee/a1b00d34d1663e016163b96e578ad521 to your computer and use it in GitHub Desktop.

Revisions

  1. Namchee created this gist Apr 28, 2021.
    34 changes: 34 additions & 0 deletions solution.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    // really quick and dirty way to solve it.

    let count = 0;

    const promisified = (time) => new Promise(resolve => {
    setTimeout(resolve, time);
    });

    async function timeoutProms(proms, c, time) {
    count++;

    await promisified(time);

    console.log(time);

    count--;

    serialCon(proms, c);
    }

    function serialCon(proms, c) {
    if (count < c && proms.length) {
    timeoutProms(proms, c, proms[0]);
    proms.shift();

    serialCon(proms, c);
    } else {
    return;
    }
    }

    const arr = [5000, 1000, 100, 300, 2000];

    serialCon(arr, 2);