Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including block-failed with all npm packages installed. Try it out:

var blockFailed = require("block-failed")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

block-failed v0.0.1

Helper method that helps failed attempts based on a key.

node-block-failed

// blocker will block for BLOCKED_DURATION_MS if ATTEMPT_COUNT failed attempts are made within ATTEMPT_DURATION_MS
blocker = blockFailed(BLOCKED_DURATION_MS, ATTEMPT_DURATION_MS, ATTEMPT_COUNT)
// blocker is now (key, on_attempt, on_block) => void
// on_attempt is on_failure => ...
// on_block is blockDurationMS => ...
...

block(ip_address, on_failure =>
{
  try
  {
    ...
  }
  catch (e)
  {
    if (!on_failure())
    {
      console.log('operation failed. please try again');
    }
  }
},
blockDurationMS =>
{
  console.log('operation blocked. please try again in', blockDurationMS, 'ms');
});

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free