lib/utility.js
function callService(service, emitter, channel, callback) {
    var argsValue = Array.prototype.slice.call(Array.prototype.slice.call(arguments)[4]);
    var callerFunc = arguments.callee.caller;
    var eventName = service.name || service._name;
    var callerArgNames = _retrieveArgumentNames(callerFunc);
    var props = {};
    for(var i = 0; i < callerArgNames.length - 1; i++) {
        props[callerArgNames[i]] = argsValue[i];
    }
    if (callback) {
        emitter.once(eventName, callback);
    }
    if (emitter.isReady(true)) {
        try {
            service({
                props: props,
                channel: channel,
                callback: createEventEmitterCallback(eventName, emitter)
            });
        } catch (err) {
            emitter.emit('error', err);
        }
    }
    return new Promise(function (fulfill, reject) {
        emitter.once('error', reject);
        emitter.once(eventName, function (result) {
            emitter.removeListener('error', reject);
            if (typeof result !== 'boolean' && result.instanceOf('mtproto.type.Rpc_error')) {
                reject(new Error(result.error_message));
            } else {
                fulfill(result);
            }
        });
    });
}
function callService(service, emitter, channel, callback) {
    var argsValue = Array.prototype.slice.call(Array.prototype.slice.call(arguments)[4]);
    var callerFunc = arguments.callee.caller;
    var eventName = service.name || service._name;
    var callerArgNames = _retrieveArgumentNames(callerFunc);
    var props = {};
    for(var i = 0; i < callerArgNames.length - 1; i++) {
        props[callerArgNames[i]] = argsValue[i];
    }
    if (callback) {
        emitter.once(eventName, callback);
    }
    if (emitter.isReady(true)) {
        try {
            service({
                props: props,
                channel: channel,
                callback: createEventEmitterCallback(eventName, emitter)
            });
        } catch (err) {
            emitter.emit('error', err);
        }
    }
    return new Promise(function (fulfill, reject) {
        emitter.once('error', reject);
        emitter.once(eventName, function (result) {
            emitter.removeListener('error', reject);
            if (typeof result !== 'boolean' && result.instanceOf('mtproto.type.Rpc_error')) {
                reject(new Error(result.error_message));
            } else {
                fulfill(result);
            }
        });
    });
}
function callService ( service , emitter , channel , callback ) { var argsValue = Array . prototype . slice . call ( Array . prototype . slice . call ( arguments ) [ 4 ] ) ; var callerFunc = arguments . callee . caller ; var eventName = service . name || service . _name ; var callerArgNames = _retrieveArgumentNames ( callerFunc ) ; var props = { } ; for ( var i = 0 ; i < callerArgNames . length - 1 ; i ++ ) { props [ callerArgNames [ i ] ] = argsValue [ i ] ; } if ( callback ) { emitter . once ( eventName , callback ) ; } if ( emitter . isReady ( true ) ) { try { service ( { props : props , channel : channel , callback : createEventEmitterCallback ( eventName , emitter ) } ) ; } catch ( err ) { emitter . emit ( 'error' , err ) ; } } return new Promise ( function ( fulfill , reject ) { emitter . once ( 'error' , reject ) ; emitter . once ( eventName , function ( result ) { emitter . removeListener ( 'error' , reject ) ; if ( typeof result !== 'boolean' && result . instanceOf ( 'mtproto.type.Rpc_error' ) ) { reject ( new Error ( result . error_message ) ) ; } else { fulfill ( result ) ; } } ) ; } ) ; }
Calls a service and infers the arguments by the caller function.
Calls a service and infers the arguments by the caller function .