resizeFunctionWorkers method
Implementation
void resizeFunctionWorkers(
int count,
WorkerFunction function, {
Map? metadata,
}) async {
if (sockets.length < count) {
for (var i = sockets.length + 1; i <= count; i++) {
var sock = createWorker(
function,
metadata: {'workerId': i}..addAll(metadata ?? {}),
);
sock._pool = this;
sock.onReceivedMessageHandler = (dynamic msg) {
if (onMessageReceivedHandler != null) {
onMessageReceivedHandler!(i, msg);
}
};
await sock.init();
sockets.add(sock);
}
} else {
reduceWorkers(count);
}
}