Refactor doom-num-cpus

Adds error handling.
This commit is contained in:
Henrik Lissner 2020-11-29 15:51:28 -05:00
parent a50db6291b
commit b426e21ef1
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -48,13 +48,23 @@ Warning: freezes indefinitely on any stdin prompt."
Tries to be portable. Returns 1 if cannot be determined."
(or doom--num-cpus
(setq doom--num-cpus
(max
1 (cond ((eq 'windows-nt system-type)
(or (ignore-errors
(string-to-number (getenv "NUMBER_OF_PROCESSORS")))
1))
(let ((cpus
(cond ((getenv "NUMBER_OF_PROCESSORS"))
((executable-find "nproc")
(string-to-number (cdr (doom-call-process "nproc"))))
((and IS-MAC (executable-find "sysctl"))
(string-to-number (cdr (doom-call-process "sysctl" "-n" "hw.ncpu"))))
(t 1))))))
(doom-call-process "nproc"))
((executable-find "sysctl")
(doom-call-process "sysctl" "-n" "hw.ncpu")))))
(max
1 (or (cl-typecase cpus
(string
(condition-case _
(string-to-number cpus)
(wrong-type-argument
(user-error "NUMBER_OF_PROCESSORS contains an invalid value: %S"
cpus))))
(consp
(if (zerop (car cpus))
(string-to-number (cdr cpus))
(user-error "Failed to look up number of processors, because:\n\n%s"
(cdr cpus)))))
1))))))