ChatCrawlersearch across public Telegram Open the app
A

As For JS - Talks

сообщение · 2025-06-30 21:34 UTC
I
id 1724672644Ссылка
(() => { // Фабрика «плавающего» промиса, который через указанное время резолвится случайным числом function makePromise(name, delay) { return new Promise(resolve => { setTimeout(() => { const value = Math.floor(Math.random() * 100); // console.log(`${name} -> resolved with`, value); resolve(value); }, delay); }); } // Исходный массив промисов: сразу отклонённых (для демонстрации any уходит в catch) const p1 = Promise.reject('initial error 1'); const p2 = Promise.reject('initial error 2'); let promises = [p1, p2]; function resolverWithSwap() { Promise.any(promises) .then(res => { console.log('Promise.any:', res); }) .catch(err => { console.warn('Promise.any rejected:', err); // Здесь мы «меняем» массив: создаём новые промисы, // которые разрешатся через 1‒2 секунды случайными числами. promises = [ makePromise('newP1', 1000), makePromise('newP2', 2000), ]; // Теперь allSettled будет смотреть именно на новые промисы Promise.allSettled(promises) .then(results => { console.log('Results of allSettled:'); results.forEach((r, i) => { if (r.status === 'fulfilled') { console.log(` promise #${i + 1} fulfilled with`, r.value); } else { console.log(` promise #${i + 1} rejected with`, r.reason); } }); }); }); } // Запускаем resolverWithSwap(); })()

Вся лента · оригинал в Telegram

Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog