<commit_before>import 'babel-regenerator-runtime';
import 'source-map-support/register';
import Application from './application';
import memoryCache from './memory-cache';
import redisCache from './redis-cache';
import httpTransport from './http-transport';

export { memoryCache, redisCache, httpTransport };

/**
 * Factory function that automatically starts the service
 * @param  {[type]}   options.name       [description]
 * @param  {[type]}   options.brokerPath [description]
 * @param  {[type]}   options.transport  [description]
 * @param  {[type]}   options.cache      [description]
 * @param  {Function} callback           [description]
 * @return {[type]}                      [description]
 */
export function connect({ name, brokerPath, transport, cache }, callback) {

  if(! (typeof arguments[0] == 'string' && typeof arguments[1] == 'string' && typeof arguments[2] !== 'function')) {

  }

  let service = new Application({ name });
  let wait = [];

  if(transport)
    wait.push(service.set('transport', transport));

  if(cache)
    wait.push(service.set('cache', cache));

  return Promise
    .all(wait)
    .then(() => service.start({ brokerPath }))
    .then(() => callback(service))
    .catch(e => {
      return service
        .stop()
        .then(() => console.log(e.stack))
        .catch(() => console.log(e.stack));
    });
};

/**
 * Default export of the application factory
 * @param  {[type]} options [description]
 * @return {[type]}         [description]
 */
export default function app(options) {
  return new Application(options);
};

app.memoryCache   = memoryCache;
app.redisCache    = redisCache;
app.httpTransport = httpTransport;



<commit_msg>Modified factory function to perform auto-start when brokerPath supplied<commit_after>import 'babel-regenerator-runtime';
import 'source-map-support/register';
import Application from './application';
import memoryCache from './memory-cache';
import redisCache from './redis-cache';
import httpTransport from './http-transport';

export { memoryCache, redisCache, httpTransport };

/**
 * Factory function that automatically starts the service if the brokerPath
 * is supplied. Otherwise it will simply return the service
 * @param  {[type]}   options.name       [description]
 * @param  {[type]}   options.brokerPath [description]
 * @param  {[type]}   options.transport  [description]
 * @param  {[type]}   options.cache      [description]
 * @param  {Function} callback           [description]
 * @return {[type]}                      [description]
 */
export default function goodly({ name, brokerPath, transport, cache }, callback) {
  let service = new Application({ name });
  let wait = [];

  if(!brokerPath)
    return service;

  if(transport)
    wait.push(service.set('transport', transport));

  if(cache)
    wait.push(service.set('cache', cache));

  return Promise
    .all(wait)
    .then(() => callback(service))
    .then(() => service.start({ brokerPath }))
    .catch(e => {
      return service
        .stop()
        .then(() => console.log(e.stack))
        .catch(() => console.log(e.stack));
    });
};

goodly.memoryCache   = memoryCache;
goodly.redisCache    = redisCache;
goodly.httpTransport = httpTransport;




{'fraction_non_alphanumeric': 0.15054095826893354, 'fraction_numerical': 0.0009273570324574962, 'mean_word_length': 3.426812585499316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '4840364', 'n_tokens_mistral': 923, 'n_tokens_neox': 892, 'n_words': 248}