<commit_before>
var Promise = require('bluebird');
var util = require('util');

module.exports = function( options, done ) {

    var seneca = this,
        senecaProto = Object.getPrototypeOf(seneca);

    //Required to promisify entity methods. Call early so we fail early if senecajs doesn't support exporting Entity
    var Entity = seneca.export('Entity');
    if (!Entity) {
        seneca.log.fatal("Seneca must be modified to return Entity through .export() before seneca-bluebird can function properly.");
        process.exit(1);
    }

    /** 
     * Core stuff
     *
     * addAsync: register handler which returns promise
     *
     * actAsync: promisified .act()
     *
     * readyAsync: promisified .ready(). Returns seneca
     *
     * clientAsync: promisified .ready()->.client(). Returns client (which is seneca)
     */

    senecaProto.addAsync = function() {
        var q = Promise.pending(),
            args = Array.prototype.slice.apply(arguments),
            fn = args.pop();

        var newfn = function(args, cb) {
            //console.log('calling on ',typeof fn,'with: ',args);
            try {
                fn.call(seneca, args).then(function(out){
                    cb(null, out);
                }).catch(function(err){
                    if (typeof err == "string") {
                        err = new Error(err);
                    }
                    cb(err);
                });
            } catch(err) { //never called?
                if (err && err.code && !err.message) 
                    err.message = err.code;
                cb(err);
            }
        };
        args.push(newfn);
        //console.log('registering async',args.length, typeof args[0], typeof args[1]);
        this.add.apply(seneca, args);
    };

    senecaProto.actAsync = function(){
        var q = Promise.pending(),
            args = Array.prototype.slice.apply(arguments);
        args.push(function(err, out){
            //console.log('async resolution',err,out);
            err ? q.reject(err) : q.resolve(out);
        });
        try {
            this.act.apply(seneca, args);<commit_msg>idiotic context fix<commit_after>
var Promise = require('bluebird');
var util = require('util');

module.exports = function( options, done ) {

    var seneca = this,
        senecaProto = Object.getPrototypeOf(seneca);

    //Required to promisify entity methods. Call early so we fail early if senecajs doesn't support exporting Entity
    var Entity = seneca.export('Entity');
    if (!Entity) {
        seneca.log.fatal("Seneca must be modified to return Entity through .export() before seneca-bluebird can function properly.");
        process.exit(1);
    }

    /** 
     * Core stuff
     *
     * addAsync: register handler which returns promise
     *
     * actAsync: promisified .act()
     *
     * readyAsync: promisified .ready(). Returns seneca
     *
     * clientAsync: promisified .ready()->.client(). Returns client (which is seneca)
     */

    senecaProto.addAsync = function() {
        var q = Promise.pending(),
            args = Array.prototype.slice.apply(arguments),
            fn = args.pop();

        var newfn = function(args, cb) {
            //console.log('calling on ',typeof fn,'with: ',args);
            try {
                fn.call(seneca, args).then(function(out){
                    cb(null, out);
                }).catch(function(err){
                    if (typeof err == "string") {
                        err = new Error(err);
                    }
                    cb(err);
                });
            } catch(err) { //never called?
                if (err && err.code && !err.message) 
                    err.message = err.code;
                cb(err);
            }
        };
        args.push(newfn);
        //console.log('registering async',args.length, typeof args[0], typeof args[1]);
        this.add.apply(seneca, args);
    };

    senecaProto.actAsync = function(){
        var q = Promise.pending(),
            args = Array.prototype.slice.apply(arguments);
        args.push(function(err, out){
            //console.log('async resolution',err,out);
            err ? q.reject(err) : q.resolve(out);
        });
        try {
            this.act.apply(this, args);
{'fraction_non_alphanumeric': 0.13165266106442577, 'fraction_numerical': 0.0014005602240896359, 'mean_word_length': 1.759175788795879, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4064476', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1154, 'n_words': 291}