This file contains 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
/** | |
* Wraps a callback in a timeout timer | |
*/ | |
function callbackWithTimeout(callback, delay) { | |
// light the fuse | |
var timeoutId = setTimeout(function(){ | |
timedCallback('timeout', null); | |
}, delay); | |
var timedCallback = function(err, result) { |
This file contains 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 _ = require('underscore'), | |
SocketIOClient = require('socket.io-client'), | |
liveSocket = require('../lib/live-socket'); | |
exports.setupClient = function(opts) { | |
return function() { | |
opts = opts || {}; | |
_.defaults(opts, { | |
url: 'http://localhost:8000', | |
options: { |
This file contains 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
// (server) server-side | |
var io = require('socket.io').listen(8000); | |
io.sockets.on('connection', function (socket) { | |
socket.emit('news', { hello: 'world' }); | |
socket.on('ping', function (data) { | |
console.log(data); | |
}); |
This file contains 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 _ = require('underscore'); | |
var idCounter = 0; | |
// Mock Socket Class used for asynchronous faking | |
var MockSocket = function() { | |
// sub-class to hook | |
// dictionary of message queues by msg | |
this.messageQueues = {}; | |
this.subscriptions = {}; |
This file contains 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
function runCrawler(obs) { | |
var self = this; | |
self.crawling = true; | |
Rx.Observable.While( | |
function() {return self.crawling}, | |
Rx.Observable.If( | |
function(){return self.crawlQueue.length > 0;}, | |
Rx.Observable.Defer(function (){ | |
var nextCrawlStep = self.crawlQueue.pop(); | |
return self.selectForCrawlLinks(nextCrawlStep.Delay(self.delay))}), |
This file contains 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
// pseudocode: ajax(request_object, callback) | |
ajax(a, function() { | |
ajax(b(a.somedata), function() { | |
ajax(c(b.somedata), function() { | |
c.finish() | |
}) | |
}) | |
}) |