@heyrohit/promise-3
Nodejs

No description

I built🔨
THIS
Files
  • index.js
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const tasks = [
  { name: 'task-1', time: 200 },
  { name: 'task-2', time: 400},
  { name: 'task-3', time: 100},
  { name: 'task-4', time: 50}
];

function getPromise(task) {
  const taskPromise = new Promise((resolve, reject) => {
    console.log(task.name + " started.");
    
    setTimeout(() => {
      console.log(task.name + " done in ", task.time, "ms.");
      resolve(task.name);
    }, task.time);
  });
  
  return taskPromise;
}

getPromise(tasks[0]).then(getPromise(tasks[1]));

node v9.7.1 linux/amd64