Skip to content

📒 Test `Promise.chain` - my own implementation of synchronously executes list of promises.

Notifications You must be signed in to change notification settings

piecioshka/test-es2015-promise-chain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test-es2015-promise-chain

More: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-promise-constructor

For what?

I would like to tests 3 static methods. Two methods are from specification

  • Promise.all
  • Promise.race

and third is my

  • Promise.chain

My Promise extension

In specification we don't have method which run list of functions (which they return Promise object) synchronously. So I decide to create method Promise.chain. I know that exists yet lib for that - https://www.npmjs.com/package/promise-chain but I will try to resolve this problem myself.

How to use it?

const list = [];

list.push(function () {
    return new Promise(function (resolve) {
        setTimeout(function () {
            resolve('first one');
        }, 1300);
    });
});


list.push(function () {
    return new Promise(function (resolve) {
        setTimeout(function () {
            resolve('second one');
        }, 300);
    });
});

// Functions are execute synchronously.
Promise.chain(list).then(function (response) {
    console.log(response[0]); // 'first one'
    console.log(response[1]); // 'second one'
});

About

📒 Test `Promise.chain` - my own implementation of synchronously executes list of promises.

Resources

Stars

Watchers

Forks