From a4720c693ff478b589b3fa2d8e2908974ff730d1 Mon Sep 17 00:00:00 2001 From: gylidian Date: Tue, 19 Nov 2019 15:54:54 +0800 Subject: [PATCH] feat: add hardware concurrency hooks --- hardware-concurrency.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 hardware-concurrency.js diff --git a/hardware-concurrency.js b/hardware-concurrency.js new file mode 100644 index 0000000..9632ede --- /dev/null +++ b/hardware-concurrency.js @@ -0,0 +1,23 @@ +let unsupported; + +if (typeof navigator !== "undefined" && "hardwareConcurrency" in navigator) { + unsupported = false; +} else { + unsupported = true; +} + +let initialHardwareConcurrency; + +if (!unsupported) { + initialHardwareConcurrency = { + numberOfLogicalProcessors: navigator.hardwareConcurrency + }; +} else { + initialHardwareConcurrency = { unsupported: true }; +} + +const useHardwareConcurrency = () => { + return { ...initialHardwareConcurrency }; +}; + +export { useHardwareConcurrency };