New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

create-run-task

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-run-task

Runs a "task" function but only executes it once while it's running. This can be useful when on the server side requesting the same external api endpoint from multiple pseudo-simultaneous incoming requests. This will ensure that you only make the request

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Runs a "task" function but only executes it once while it's running. This can be useful when on the server side requesting the same external api endpoint from multiple pseudo-simultaneous incoming requests. This will ensure that you only make the request to the external api endpoint once for all incoming request util it's complete.

/**
 * @name createRunTask
 * @function
 * @param {Object} [options]
 * @param {Number} [options.defaultTimeout] Defaults to 10000
 * @returns {runTask}
 */


/**
 * @name runTask
 * @function
 * @param {String} name
 * @param {Function} task
 * @param {Object} [options]
 * @param {Number} [options.timeout] Defaults to defaultTimeout
 * @returns {Promise}
 */


let counter = 0;
const runTask = createRunTask();
const name = 'foobar';
const task = () => new Promise((resolve) => {
  counter += 1;
  setTimeout(() => resolve(counter), 100);
});

Promise.all([
  runTask(name, task),
  runTask(name, task),
  runTask(name, task),
  runTask(name, task),
  runTask(name, task)
])
  .then(result => assert.deepEqual(result, [ 1, 1, 1, 1, 1 ]))

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc