🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

exec-stack

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

exec-stack

```javascript $ npm install exec-stack ```

1.1.0
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

ExecStack npm version

Installation

$ npm install exec-stack

Example

const ExecStack = require('exec-stack');
const stack = new ExecStack();

stack.use('cars', next => {
	console.log('I\'m specifically interested in cars');
	next();
});

stack.use((event, next) => {
	console.log('I\'m generic. Hence interested in anything, also', event);
	next();
});

stack.run('cars');
stack.run('bikes').then(console.log('Done!'));

Output:

I'm specifically interested in cars
I'm generic. Hence interested in anything, also cars
I'm generic. Hence interested in anything, also bikes
Done!

Methods

Optional arguments are written in cursive.

.use(event, callback)

Push a middleware to the stack. If event is omitted, the callback will be called for every execution of the stack.
Returns the position of the middleware in the stack.

.unuse(position)

Removes a specified middleware from the stack. The middleware is being referenced by a number representing its position in the stack.

.run(event, ...args)

Any other argument that is given to .execute() will also be passed to the functions in the stack.
Returns a promise that is being resolved after everything has finished.
If any middleware calls next.throw() the promise will be rejected.

.context(context)

Set the context to be applied to middleware. When context is omitted it will be cleared to an empty object.

Breaking the loop

If you want to stop the execution of the stack use next.throw(*error*) which also will reject the promise returned by .run()

FAQs

Package last updated on 23 Feb 2016

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