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

bluebird

Package Overview
Dependencies
Maintainers
1
Versions
223
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bluebird

Full featured Promises/A+ implementation with exceptionally good performance

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32M
increased by6.97%
Maintainers
1
Weekly downloads
 
Created

What is bluebird?

Bluebird is a fully-featured Promise library for JavaScript. It allows for advanced features such as promise chaining, concurrency control, and error handling. It is known for its performance and useful utilities for working with asynchronous operations in JavaScript.

What are bluebird's main functionalities?

Promisification

Converts Node.js callback-style functions to return a Bluebird promise. In this example, the 'fs' module's 'readFile' function is promisified to use promises instead of callbacks.

const Promise = require('bluebird');
const fs = Promise.promisifyAll(require('fs'));

fs.readFileAsync('example.txt', 'utf8').then(contents => {
  console.log(contents);
}).catch(error => {
  console.error('Error reading file', error);
});

Promise Chaining

Allows for chaining multiple asynchronous operations where each step waits for the previous one to complete. Errors can be caught and handled gracefully.

const Promise = require('bluebird');

Promise.resolve(1)
  .then(x => x + 1)
  .then(x => { throw new Error('Something went wrong'); })
  .catch(Error, e => console.error(e.message));

Concurrency Control

Provides utilities to control the concurrency of multiple promises. The 'map' function here runs a maximum of two promises in parallel.

const Promise = require('bluebird');

const tasks = [/* array of functions that return promises */];

Promise.map(tasks, task => task(), { concurrency: 2 })
  .then(results => {
    console.log('All tasks completed', results);
  });

Error Handling

Offers a clean syntax for error handling in promise chains. The 'try' method is used to start a promise chain with error handling.

const Promise = require('bluebird');

Promise.try(() => {
  throw new Error('Something failed');
}).catch(Error, e => {
  console.error('Caught an error:', e.message);
});

Other packages similar to bluebird

Keywords

FAQs

Package last updated on 03 Mar 2014

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