Source
reduceWorkers(int count) async { if (sockets.length > count) { var toRemove = sockets.length - count; List<WorkerSocket> socks = sockets .skip(count) .take(toRemove) .toList(); for (var sock in socks) { await sock.close(); sock.kill(); sockets.remove(sock); } } }