stuff. |
var createBus = function() { | |
var me = {} | |
var _handlers = {} | |
var _events = [] | |
me.space = function(name) { | |
return { | |
on: function(address) { | |
return { |
### Keybase proof | |
I hereby claim: | |
* I am mpj on github. | |
* I am mpj (https://keybase.io/mpj) on keybase. | |
* I have a public key whose fingerprint is 882A BDDF DAC0 B6CB 5EB3 078A 9BE9 D285 0A78 B179 | |
To claim this, I am signing this object: |
var findToArray = function(collection, query) { | |
var deferred = Q.defer(); | |
var cursor = collection.find(query); | |
collection.find({}).toArray(function(error, result) { | |
if (error) | |
deferred.reject(error) | |
else | |
deferred.resolve(result) | |
}) |
Snurra Broker is a message bus with a stream interface. Below is an example on how to interact with it. Snurra plays very nicely with libraries like highland.js (http://highlandjs.org/), but Snurra Broker does not depend on it - snurra creates plain vanilla node streams, and will work with any stream library.
_ = require 'highland'
Broker = require 'snurra-broker'
broker = new Broker()
# Calling the broker with a string (a channel name), creates a
orderStream = broker('orders') | |
unhandledOrdersStream = | |
_(broker('orders')).filter (order) -> not order.shippingdate | |
unhandledOrdersStream.each (order) -> | |
# do stuff with order that is not handled | |
Snurra is a fresh take on message bus pattern by using streams as the interface instead of the more traditional callback pattern.
Let's walk through the basic syntax of Snurra.
var _ = require('highland');
var snurra = require('snurra');
var bus = snurra();
The primary ambition of Snurra is to make it easier to see what is happening inside your program, mock external dependencies and to verify behavior.
Snurra tries looks upon the API consumer like a user, rather than a developer that can be expected to fiddle around with unclear interfaces and vague documentation.
Snurra tries to expose vanilla node streams as cleanly as possible and not abstract them away from the user, so that the user can take advantage of node stream documentation and stream manipulation libraries like highland.js. It is willing to sacrifice being terse or hand-holding in order to be understandable and re-usable.
WebSocket = require 'ws' | |
_ = require 'highland' | |
isNumber = require 'mout/lang/isNumber' | |
listen = (account) -> | |
stream = _() | |
ws = new WebSocket('ws://live.stellar.org:9001'); | |
ws.on 'open', -> | |
payload = JSON.stringify | |
"command" : "subscribe" |