Socket
Socket
Sign inDemoInstall

bubble

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bubble

Domains for the poor man. Flow-control for cascading callbacks. Error handling. Aborts groups of callbacks. With timeouts.


Version published
Maintainers
1
Install size
6.04 kB
Created

Readme

Source

Bubble Build Status

Domains for the poor man.

Flow-control for cascading callbacks.

Aborts groups of callbacks.

With timeouts (if you will).

Inspired by substack/node-toss.

Example:

var bubble = require('bubble')
var timeout = 2000

require('http').createServer(function(req, res) {

  var b = bubble(timeout, function(err, file_c_data) {
    if (err) {
      res.writeHead(500)
      res.write(err.message)
    } else {
      res.end(file_c_data)
    }
  });

  fs.readFile('./file_a', b(function(file_a_data) {
    fs.readFile('./file_b', b(function(file_b_data) {
      fs.readFile('./file_c', b())
    })
  }))
})

You can also leave out the timeout:

var b = bubble(function(err, file_c_data) {
  // ...
});

fs.readFile('./file_a', b(function(file_a_data) {
  // ...
});

You can also leave out the last wrapper if you're not doing more IO and don't care about the callback values:

var bubble = require('bubble')
var timeout = 2000

require('http').createServer(function(req, res) {

  var file_c_data;

  var b = bubble(timeout, function(err) {
    if (err) {
      res.writeHead(500)
      res.write(err.message)
    } else {
      res.end(file_c_data)
    }
  });

  fs.readFile('./file_a', b(function(file_a_data) {
    fs.readFile('./file_b', b(function(file_b_data) {
      fs.readFile('./file_c', function(err, value) {
        if (err) {
          // handle error
        }
        file_c_data = data;
        console.log('file ended, but bubble callback will be called anyway');
      })
    })
  }))
})

FAQs

Last updated on 21 Mar 2012

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc