JSFiddle - React, Tailwind, and code Playground

by Vladymyr Shevchuk

JavaScript

function connectToSocket() {
	return new Promise((resolve, reject) => {
  	return reject();
  }
}

function tryReconnect() {
  const attemptCount = [1, 2, 3, 4];

  let timer = 1000;

  attemptCount.reduce((p, i) => p.then(
    () => new Promise(
      resolve => {
        timer *= i;
        setTimeout(() => {
          connectToSocket();
          //resolve();
        }, timer);
      },
      reject => {
      
      })
    ),
    Promise.resolve()
  );
}