Пример #1
0
    _pop_and_send: function () {
        if (this.res.length === 0) {
            // dont stitch responses as well.
            log.debug("%s pop_and_send - Holding 0 ro - return", this.sid);
            return;
        }
        
        if (!this.pending_stitched_responses.length) {
            this._stitch_new_response();
        }

        if (this.pending_stitched_responses.length) {
            var ro = this.get_response_object();
            log.debug("%s pop_and_send - ro: %s, pending_stitched_responses: %s - sending", this.sid, us.isTruthy(ro), this.pending_stitched_responses.length);
            
            var _p = this.pending_stitched_responses.shift();
            var response = _p.response;
            var stream = _p.stream;

            // We dont do anything on error, we assume
            // that the client will request the missing
            // RID. 
            this._send_no_requeue(ro, response);

            // We try sending more queued responses
            this.send_pending_responses();
        } else {
            log.debug("%s pop_and_send - nothing to send, 0 pending - return");
        }
    },
    send_pending_responses: function () {
        log.trace("%s send_pending_responses - pending.length: %s, Holding %d response objects", this.sid, this.pending_stitched_responses.length, this.res.length);
        
        while (true) {
            if (this.res.length === 0) {
                // dont stitch responses as well.
                break;
            }
        
            if (!this.pending_stitched_responses.length) {
                this._stitch_new_response();
            }

            if (this.pending_stitched_responses.length > 0) {
                var ro = this.get_response_object();
                log.trace("%s send_pending_responses - ro: %s, pending_stitched_responses: %s - sending", this.sid, us.isTruthy(ro), this.pending_stitched_responses.length);
            
                var _p = this.pending_stitched_responses.shift();
                var response = _p.response;
                var stream = _p.stream;

                // We dont do anything on error, we assume
                // that the client will request the missing
                // RID. 
                this._send_no_requeue(ro, response);

                // We try sending more queued responses
                this.send_pending_responses();
            } else {
                log.trace("%s send_pending_responses - nothing to send, 0 pending - return", this.sid);
                break;
            }
        }
    },