evented stack
Evented, Array styled, stack for node
npm install evented-stack
Why
Wanted an Array like queue with juicy behaviour and custom flow control.
Inspired by creationix's stack and jessetane's queue
General idea
On mind:
Get an Array subClass out of the module
after which one can add flow control.
- See
./lib/ArraySubClass.js
or the awesome kangax post on how to do that.
Have the thing inherit from EventEmitter so one can plug flow control on the known array methods.
Niceness:
- One should be able to switch the events on and off.
- set and get methods to store simple data between layers of the stack.
Defaults:
- For iterative methods such as
forEach
, events are emitted. See below example for more information on this.
Note: right you can push everything to the stack. In the future that might change.
Usage
As an example, lets make a middleware that will measure the time of a request.
var http = ;var Stack = ; // Array subClass - EventEmittervar stack = ; // Elements of the stackstack // Eventsstack
At this point the stack is
console Function: stackFn1 Function: stackFn2 console start: Function: g listener: Function: onStart next: Function: onNext end: Function: onEnd
Now we can hook it up to a http.Server
var Server = http Server
API
At this point the package is still on flux. Right know you can expect, Array
and EventEmitter
like api.
If you are curious look at ./lib/Stack.js
. In any case this might change
License
MIT