UNPKG

@waboyz-baileys/shared

Version:

21 lines (20 loc) 736 B
import fastq from 'fastq'; import { withTimeout } from './withTimeout.js'; export async function shutdownServices(services, concurrency = 1) { return new Promise((resolve) => { const queue = fastq.promise(async ({ label, fn, timeout, }) => { try { await withTimeout(label, () => fn(), timeout); console.info(`✅ ${label} shut down.`); } catch (err) { console.error(`❌ ${label} shutdown failed:`, err); } }, concurrency); services.forEach(service => queue.push(service)); queue.drain = () => { console.info('📦 All shutdown tasks completed.'); resolve(); }; }); }