Created
April 17, 2018 08:03
-
-
Save n1ru4l/b17d69cf47b4a4b6ca7526efd7d68374 to your computer and use it in GitHub Desktop.
Limit stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pLimit = require('p-limit'); | |
const os = require('os'); | |
const fs = require('fs'); | |
const fsLimit = pLimit(process.env.UV_THREADPOOL_SIZE || 64); | |
const processLimit = pLimit(os.cpus().length); | |
const mkdir = (...args) => fsLimit(() => promisify(fs.mkdir)(...args)); | |
const writeFile = (...args) => fsLimit(() => promisify(fs.writeFile)(...args)); | |
const readFile = (...args) => fsLimit(() => promisify(fs.readFile)(...args)); | |
const stat = (...args) => fsLimit(() => promisify(fs.stat)(...args)); | |
const spawn = (...args) => processLimit(() => _spawn(...args)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment