Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

opossum

Package Overview
Dependencies
Maintainers
9
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opossum

A fail-fast circuit breaker for promises and callbacks

  • 8.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
279K
increased by2.96%
Maintainers
9
Weekly downloads
 
Created

What is opossum?

Opossum is a Node.js package that implements the circuit breaker pattern. It helps in making your application more resilient by preventing cascading failures and providing fallback mechanisms when external services fail or become unresponsive.

What are opossum's main functionalities?

Circuit Breaker

This feature allows you to wrap a function that might fail with a circuit breaker. If the function fails too many times, the circuit breaker will open and prevent further calls to the failing function until it recovers.

const CircuitBreaker = require('opossum');

async function asyncFunctionThatCouldFail() {
  // Simulate a function that could fail
  return 'Success!';
}

const breaker = new CircuitBreaker(asyncFunctionThatCouldFail);

breaker.fire()
  .then(console.log)
  .catch(console.error);

Fallback

This feature allows you to specify a fallback function that will be called when the main function fails. This can be useful for providing a default response or alternative behavior when the primary function is unavailable.

const CircuitBreaker = require('opossum');

async function asyncFunctionThatCouldFail() {
  throw new Error('Failed!');
}

const breaker = new CircuitBreaker(asyncFunctionThatCouldFail, {
  fallback: () => 'Fallback response'
});

breaker.fire()
  .then(console.log)
  .catch(console.error);

Status Monitoring

This feature allows you to monitor the status of the circuit breaker. You can listen for events such as 'open', 'halfOpen', and 'close' to take appropriate actions based on the state of the circuit breaker.

const CircuitBreaker = require('opossum');

async function asyncFunctionThatCouldFail() {
  return 'Success!';
}

const breaker = new CircuitBreaker(asyncFunctionThatCouldFail);

breaker.on('open', () => console.log('Circuit breaker opened!'));
breaker.on('halfOpen', () => console.log('Circuit breaker half-open!'));
breaker.on('close', () => console.log('Circuit breaker closed!'));

breaker.fire()
  .then(console.log)
  .catch(console.error);

Other packages similar to opossum

Keywords

FAQs

Package last updated on 25 May 2023

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