Skip to content

Instantly share code, notes, and snippets.

@bbozo
Created October 14, 2014 14:15
Show Gist options
  • Save bbozo/0c55f168e4fe6fb021fd to your computer and use it in GitHub Desktop.
Save bbozo/0c55f168e4fe6fb021fd to your computer and use it in GitHub Desktop.
require 'celluloid/io'
require 'http'
class Client
include Celluloid::IO
def transmit
HTTP.get('http://127.0.0.1:1337', socket_class: Celluloid::IO::TCPSocket)
end
end
pool = Client.pool
10.times.map{ pool.future.transmit }.map(&:value)
require 'celluloid/io'
require 'http'
class Client
include Celluloid::IO
def transmit
HTTP.get('http://127.0.0.1:1337', socket_class: Celluloid::IO::TCPSocket)
end
end
client = Client.new
10.times.map{ client.future.transmit }.map(&:value)
var http = require('http');
var count = 0;
http.createServer(function (req, res) {
count = count + 1;
console.log('Parallel client opens connection ' + count);
req.connection.on('close',function(){
count = count - 1;
console.log('Parallel client closes connection ' + count);
});
setTimeout(function(){
res.writeHead(200, {'Content-Type': 'application/json'});
res.end('{"foo":"boo"}');
}, 2000);
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment