<commit_before>package pman.ipc;

import tannus.io.*;
import tannus.ds.*;
import tannus.sys.*;

import edis.concurrency.*;
import edis.concurrency.WorkerPacket;

import haxe.extern.EitherType;
import haxe.Constraints.Function;
import electron.*;

using StringTools;
using tannus.ds.StringUtils;
using tannus.ds.ArrayTools;
using Lambda;
using Slambda;

class BaseIpcCommands {
    /* Constructor Function */
    public function new():Void {
        _pb = new EventDispatcher();
        @:privateAccess _pb.__checkEvents = false;
        _replyListeners = new Dict();
        _listened = new Set();
    }

/* === Utility Methods === */

    public inline function push(channel: String):Void {
        send(channel, null, null);
    }

    /**
      * bind a function to a channel
      */
    public function fbind(exportName:String, func:Function, sendReturn:Bool=false):Void {
        on(exportName, function(packet) {
            var args:Array<Dynamic> = cast packet.data;
            if (args == null) {
                args = [];
            }
            var result:Dynamic = Reflect.callMethod(null, func, args);
            if ( sendReturn ) {
                packet.reply( result );
            }
        });
    }

    /**
      * utility method to feel more like remotely calling a function
      * TODO (implement the callback portion of that)
      */
    public inline function acall(name:String, ?args:Array<Dynamic>, ?callback:Function, ?encoding:WorkerPacketEncoding):Void {
        return send(name, args, encoding);
    }

    /**
      * underlying method for [call]
      */
    private function _acall(params: Array<Dynamic>):Void {
        var name:String = '';
        var args:Null<Array<Dynamic>> = null;
        var encoding:Null<WorkerPacketEncoding> = null;
        var callback:Null<Function> = null;

        if (params.length == 0) {
            throw 'Error: Invalid "call"';
        }

        if ((params[0] is String)) {
            name = cast params.shift();
        }

        if ((params.last() is String) && WorkerPacketEncoding.isWorkerPacketEncoding(params.last())) {
            encoding = params.pop();
        }
<commit_msg>added new 'call' method to pman.ipc.BaseIpcCommands<commit_after>package pman.ipc;

import tannus.io.*;
import tannus.ds.*;
import tannus.sys.*;

import edis.concurrency.*;
import edis.concurrency.WorkerPacket;

import haxe.extern.EitherType;
import haxe.Constraints.Function;
import electron.*;

using StringTools;
using tannus.ds.StringUtils;
using tannus.ds.ArrayTools;
using Lambda;
using Slambda;

class BaseIpcCommands {
    /* Constructor Function */
    public function new():Void {
        _pb = new EventDispatcher();
        @:privateAccess _pb.__checkEvents = false;
        _replyListeners = new Dict();
        _listened = new Set();

        call = Reflect.makeVarArgs( _acall );
    }

/* === Utility Methods === */

    public inline function push(channel: String):Void {
        send(channel, null, null);
    }

    /**
      * bind a function to a channel
      */
    public function fbind(exportName:String, func:Function, sendReturn:Bool=false):Void {
        on(exportName, function(packet) {
            var args:Array<Dynamic> = cast packet.data;
            if (args == null) {
                args = [];
            }
            var result:Dynamic = Reflect.callMethod(null, func, args);
            if ( sendReturn ) {
                packet.reply( result );
            }
        });
    }

    /**
      * "method" to 'call' a method remotely
      */
    public var call: Dynamic;

    /**
      * utility method to feel more like remotely calling a function
      * TODO (implement the callback portion of that)
      */
    public inline function acall(name:String, ?args:Array<Dynamic>, ?callback:Function, ?encoding:WorkerPacketEncoding):Void {
        return send(name, args, encoding);
    }

    /**
      * underlying method for [call]
      */
    private function _acall(params: Array<Dynamic>):Void {
        var name:String = '';
        var args:Null<Array<Dynamic>> = null;
        var encoding:Null<WorkerPacketEncoding> = null;
        var callback:Null<Function> = null;

        if (params.length == 0) {
            throw 'Error: Invalid "call"';
        }

        if ((params[0] is String)) {
            name = cast params.shift();
        }

        if ((params.last() is String) && WorkerPacketEncoding.isWorkerPacketEncoding(params.last())) {
            encoding = params.pop();
        }

{'fraction_non_alphanumeric': 0.12107127047366091, 'fraction_numerical': 0.0008853474988933156, 'mean_word_length': 2.3498888065233507, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '1761553', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1271, 'n_words': 328}