Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- const func1 = (res) => {
- return new Promise ((res,rej) => {
- setTimeout(() => {
- console.log('1');
- res();
- }, 500);
- });
- };
- const func2 = (res) => {
- return new Promise((res,rej) => {
- setTimeout(() => {
- console.log('2');
- res();
- }, 100);
- });
- };
- const func3 = (res) => {
- return new Promise((res,rej) => {
- setTimeout(() => {
- console.log('3');
- res();
- }, 250);
- });
- };
- const promises = [];
- const doPassword = true;
- if ( doPassword ) {
- promises.push(func1);
- promises.push(func2);
- }
- promises.push(func3);
- promises.reduce(function(p, func) {
- return p.then(() => func());
- }, Promise.resolve(null));
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">const func1 = (res) => {
- return new Promise ((res,rej) => {
- setTimeout(() => {
- console.log('1');
- res();
- }, 500);
- });
- };
- const func2 = (res) => {
- return new Promise((res,rej) => {
- setTimeout(() => {
- console.log('2');
- res();
- }, 100);
- });
- };
- const func3 = (res) => {
- return new Promise((res,rej) => {
- setTimeout(() => {
- console.log('3');
- res();
- }, 250);
- });
- };
- const promises = [];
- const doPassword = true;
- if ( doPassword ) {
- promises.push(func1);
- promises.push(func2);
- }
- promises.push(func3);
- promises.reduce(function(p, func) {
- return p.then(() => func());
- }, Promise.resolve(null));
- </script></body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement