Skip to content

Instantly share code, notes, and snippets.

@n1ru4l
Created April 17, 2018 08:03
Show Gist options
  • Save n1ru4l/b17d69cf47b4a4b6ca7526efd7d68374 to your computer and use it in GitHub Desktop.
Save n1ru4l/b17d69cf47b4a4b6ca7526efd7d68374 to your computer and use it in GitHub Desktop.
Limit stuff
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