eventuate
Handle events without emitters. If we had to do it all over again, we might do it this way...
example
var eventuate = require('eventuate'),
assert = require('assert')
var request = eventuate()
function onRequest (req) {
}
request(onRequest)
request().then(function nextRequest (req) {
})
assert(request.hasConsumer)
request.produce({ url: '/test' })
request.remove(onRequest)
api
var eventuate = require('eventuate')
var event = eventuate()
Create an object, event
, that represents a consumable event type.
event(consumer)
Consume events with the consumer
function, which should have the signature
function (data) {}
. When an event is produced, it will be passed to the consumer
function as the first and only argument.
When invoked this way, the return value of event()
is undefined.
var promise = event()
When event()
is invoked without a consumer, it returns a Promise
object
representing the next produced event.
event.produce(data)
Produce an event. All event
consumer functions will be called with data
, and
the Promise
representing the next event will be resolved with data
.
event.remove(consumer)
Remove the formerly added consumer
, so that it will not be called with future produced
events.
testing
npm test [--dot | --spec] [--grep=pattern]
Specifying --dot
or --spec
will change the output from the default TAP style.
Specifying --grep
will only run the test files that match the given pattern.
coverage
npm run coverage [--html]
This will output a textual coverage report. Including --html
will also open
an HTML coverage report in the default browser.