detect static method

int detect({
  1. required ProcFileReader reader,
  2. required int numberOfProcessors,
  3. required bool isLinux,
})

Works out the usable CPUs from the files the reader gives. Tests pass a fake reader.

Implementation

static int detect({
  required ProcFileReader reader,
  required int numberOfProcessors,
  required bool isLinux,
}) {
  int count = numberOfProcessors;
  if (!isLinux) {
    return count < 1 ? 1 : count;
  }
  count = _min(count, parseCpusAllowed(reader.read('/proc/self/status')));
  count = _min(count, _quota(reader));
  return count < 1 ? 1 : count;
}