This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Uses `Rx.Observable.using` to provide resource-collected Observable stream that produces values | |
* whenever the websocket receives any of the named events passed in as arguments. | |
* | |
* @param {string[]} events - named events to bind listeners to | |
* @returns {Rx.Observable<Array>} | |
*/ | |
bind(...events) { | |
return Rx.Observable.using(() => { | |
//keep a reference to listener functions so we can remove them later |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var source = Rx.Observable.using( | |
() => { | |
var conn, | |
disposable = Rx.Observable.fromNodeCallback(this.pool.getConnection, this.pool)() | |
.doOnNext((connection) => { | |
conn = connection | |
}); | |
disposable.dispose = () => { | |
if (conn) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rx = require('rx'); | |
/** | |
* Generate a 'sliding window' of the input time series. Please note that this function assumes that the observable | |
* input series is a linear time series, that is: `selector(n) < selector(n+1)`. Otherwise things will get weird. | |
* | |
* @param windowSizeMs - size of the sliding window in ms | |
* @param {function} [selector] - selector function that obtains the unix timestamp value for a given item | |
* @param {Rx.Scheduler} [scheduler] - optional scheduler | |
* @returns {Rx.Observable<T>} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Stomp = require('stomp-client'); | |
var client = new Stomp(host, port, user, password, '1.1', vhost); | |
client.connect(onConnect, onError); | |
function onConnect(sessId) { | |
//subscribe to queues etc | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Rx = require('rx'); | |
function doSomeAsyncThing(code) { | |
return Rx.Observable.return({ | |
a: "product a", | |
b: "product b", | |
c: "product c", | |
d: "product d" | |
}[code]).delay(500 + (Math.random() * 5000)); | |
} |