Socket
Socket
Sign inDemoInstall

chainsaw

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chainsaw

Build chainable fluent interfaces the easy way... with a freakin' chainsaw!


Version published
Weekly downloads
2.7M
decreased by-15.46%
Maintainers
0
Weekly downloads
 
Created

What is chainsaw?

The chainsaw npm package provides a way to build chainable and interruptible APIs that can be used to create fluent interfaces in JavaScript. It allows developers to create a sequence of actions that can be paused, resumed, and controlled in a flexible manner.

What are chainsaw's main functionalities?

Chainable API creation

This code sample demonstrates how to create a simple chainable API using chainsaw. The 'do' method is defined within the Chainsaw constructor, and it uses 'saw.next()' to proceed to the next link in the chain after a timeout.

var Chainsaw = require('chainsaw');
var saw = Chainsaw(function (saw) {
  this.do = function (cb) {
    setTimeout(function () {
      cb(1);
      saw.next();
    }, 1000);
  };
});

saw.do(function (n) {
  console.log(n);
}).do(function (n) {
  console.log(n + 1);
});

Interruptible execution

This code sample shows how to create an interruptible chain where the 'interrupt' method stops the execution of the chain. The 'wait' method sets a timeout before proceeding to the next action.

var Chainsaw = require('chainsaw');
var saw = Chainsaw(function (saw) {
  this.wait = function (delay) {
    setTimeout(saw.next, delay);
    return this;
  };
  this.interrupt = function () {
    saw.stop();
  };
});

saw.wait(1000).interrupt().wait(1000);

Other packages similar to chainsaw

Keywords

FAQs

Package last updated on 18 Jun 2011

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