const singleBusinessLogic = (function () {
const pending = [];
function finish(error, response) {
pending.forEach(callback => callback(error, response));
pending.length = 0;
}
return function (id, callback) {
if (pending.length === 0) {
fetch(`https://jsonplaceholder.typicode.com/users/${id}`)
.then(response => response.json())
.then(response => finish(null, response))
.catch(error => finish(error));
}
pending.push(callback);
};
})();
singleBusinessLogic(1, (error, data) => {
if (!error) {
console.log(data);
}
});
singleBusinessLogic(2, (error, data) => {
if (!error) {
console.log(data);
}
});
setTimeout(function () {
singleBusinessLogic(3, (error, data) => {
if (!error) {
console.log(data);
}
});
singleBusinessLogic(4, (error, data) => {
if (!error) {
console.log(data);
}
});
}, 1000);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-background-clip: text;
-moz-text-fill-color: transparent;
-ms-background-clip: text;
-ms-text-fill-color: transparent;
background-clip: text;
text-fill-color: transparent;