1
\$\begingroup\$

I'm trying to get some confidence with RXJS and FRP. This code handles file sharing via socket.io. I need some advice about general RXJS style and reactive programming.

io.sockets.on('connection', function (socket) {
  var msgStream = Rx.Observable.fromEvent(socket, 'message');
  msgStream.filter(function(x) {
    return x.type === 'get';
  }).do(function() {
    socket.send({type: 'start'});
  }).do(function() {
    msgStream.filter(function (x) { return x.type === 'next'; })
      .zip(
        RxNode.fromReadableStream(
          fs.createReadStream('file.mpg')
        ),
        function(a, b) {·
          return [a, b];
        }
      )
      .pluck('1')
      .do(function(data) {
        socket.send({type: 'chunk', data: data});
      }).subscribe(undefined, undefined, function() {
        socket.send({type: 'end'});
      });
  }).subscribe();
});
\$\endgroup\$
  • \$\begingroup\$ What happens for larger files? \$\endgroup\$ – Simon Forsberg Jul 30 '15 at 16:14
  • \$\begingroup\$ It takes something like 10 minutes to send file 400Mb weight \$\endgroup\$ – kharandziuk Jul 30 '15 at 16:16
  • \$\begingroup\$ And how fast is your internet? And how fast is the internet of the receiving end? How long does it take to send a 40 MB file? \$\endgroup\$ – Simon Forsberg Jul 30 '15 at 16:18
  • \$\begingroup\$ I'm running the application locally. Actually, the question isn't about performance. I added some explanation \$\endgroup\$ – kharandziuk Jul 30 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.