<commit_before>#!/usr/bin/env node

var amqp = require('amqplib');

var conn = amqp.connect('amqp://localhost');
conn.then(createChannel).then(null, console.warn);

function createChannel(conn) {
  process.once('SIGINT', function() { conn.close(); });
  return conn.createChannel().then(consume);
}

function consume(ch) {
  var ok = ch.assertQueue('rpc_queue', {durable: false});
  ok = ok.then(function() {
    ch.prefetch(1);
    return ch.consume('rpc_queue', reply);
  });

  return ok.then(function(_ignore) {
    console.log(' [x] Awaiting RPC requests');
  });

  function reply(msg) {
    var n = parseInt(msg.content.toString());
    console.log(' [.] fib(%d)', n);
    var response = fib(n);
    ch.sendToQueue( msg.properties.replyTo,
        new Buffer(response.toString()),
        {correlationId: msg.properties.correlationId});
    ch.ack(msg);
  }
}

function fib(n) {
  if(n == 0)
    return 0;
  else if(n == 1)
    return 1;
  else
    return fib(n-1) + fib(n-2);
}<commit_msg>refactored rpc_server.js<commit_after>#!/usr/bin/env node

var amqp = require('amqplib/callback_api');

amqp.connect('amqp://localhost', function(err, conn) {
  conn.createChannel(function(err, ch) {
    var q = 'rpc_queue';

    ch.assertQueue(q, {durable: false});
    ch.prefetch(1);
    console.log(' [x] Awaiting RPC requests');
    ch.consume(q, function reply(msg) {
      var n = parseInt(msg.content.toString());
      var r = fibonacci(n);

      console.log(" [.] fib(%d)", n);

      ch.sendToQueue(msg.properties.replyTo,
        new Buffer(r.toString()),
        {correlationId: msg.properties.correlationId});

      ch.ack(msg);
    });
  });
});

function fibonacci(n) {
  if (n == 0 || n == 1)
    return n;
  else
    return fibonacci(n - 1) + fibonacci(n - 2);
}
{'fraction_non_alphanumeric': 0.1821247892074199, 'fraction_numerical': 0.006745362563237774, 'mean_word_length': 3.341463414634146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2473483', 'n_tokens_mistral': 650, 'n_tokens_neox': 630, 'n_words': 126}