<commit_before>/*
 * Copyright 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * Please see distribution for license.
 */
$.register_module({
    name: 'og.api.rest.subscribe',
    dependencies: ['og.api.common', 'og.api.rest', 'og.common.routes'],
    obj: function () {
        var common = og.api.common;
        var api = og.api.rest;
        var subscribe;
        var RESUBSCRIBE = 10000;
        var warn = og.dev.warn;
        subscribe = api.handshake.get.partial({handler: function (result) {
            var listen, fire_updates;
            if (result.error) {
                warn(api.name + ': handshake failed\n', result.message);
                return setTimeout(subscribe, RESUBSCRIBE);
            }
            api.id = result.data['clientId'];
            fire_updates = function (reset, result) {
                var current = og.common.routes.current();
                if (reset && api.disconnected) {
                    api.disconnected = false;
                    api.fire('reconnect');
                }
                // throw out stale registrations
                api.registrations = api.registrations.filter(function (reg) { return !common.request_expired(reg, current); });
                // fire all updates if connection is reset
                if (reset) {
                    api.registrations = api.registrations.filter(
                        function (reg) {return reg.update($.extend({reset: true}, reg)) && false; }
                    );
                    return api.registrations;
                }
                result.data.updates.filter(function (update) {
                    var simple = typeof update === 'string', promise, request;
                    if (!simple && (promise = (request = api.outstanding_requests[update.id]) && request.promise)) {
                        promise.deferred.resolve({
                            error: false, data: null, meta: {id: update.message.split('/').pop()}, promise: promise.id
                        });
                        delete api.outstanding_requests[promise.id];
                    }
                    return simple;
                }).forEach(
                    function (update) {
                        var lcv, reg;
                        var len = api.registrations.length;
                        for (lcv = 0; lcv < len; lcv += 1) {
                            reg = api.registrations[lcv];
                            if (reg && reg.url === update) {
                                api.registrations[lcv] = null;
                                reg.update(reg);
                            }
                        }
                        api.registrations = api.registrations.filter(Boolean);
                    }
                );
            };
            fire_updates(true, null); // there are no registrations when subscribe() is called unless the connection's been reset
            listen = function () {
                api.updates.get({handler: function (result) {
                    if (result.error) {
                        if (!api.disconnected) {
                            api.disconnected = true;
                            api.fire('disconnect');
                            api.id = null;
                        }
                        warn(api.name + ': subscription failed\n', result.message);
                        return setTimeout(subscribe, RESUBSCRIBE);
                    }
                    if (!result.data || !result.data.updates.length) {
                        return setTimeout(listen, common.INSTANT);
                    }
                    fire_updates(false, result);
                    setTimeout(listen, common.INSTANT);
                }});
            };
            listen();
        }});
        return subscribe;
    }<commit_msg>PLAT-4546 - Revert unwanted changes<commit_after>/*
 * Copyright 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
 * Please see distribution for license.
 */
$.register_module({
    name: 'og.api.rest.subscribe',
    dependencies: ['og.api.common', 'og.api.rest', 'og.common.routes'],
    obj: function () {
        var common = og.api.common, api = og.api.rest, str = common.str, check = common.check,
            subscribe, RESUBSCRIBE = 10000 /* 10s */, warn = og.dev.warn;
        return subscribe = api.handshake.get.partial({handler: function (result) {
            var listen, fire_updates;
            if (result.error)
                return warn(api.name + ': handshake failed\n', result.message), setTimeout(subscribe, RESUBSCRIBE);
            api.id = result.data['clientId'];
            (fire_updates = function (reset, result) {
                var current = og.common.routes.current();
                if (reset && api.disconnected) (api.disconnected = false), api.fire('reconnect');
                api.registrations = api.registrations // throw out stale registrations
                    .filter(function (reg) {return !common.request_expired(reg, current);});
                if (reset) return api.registrations = api.registrations // fire all updates if connection is reset
                    .filter(function (reg) {return reg.update($.extend({reset: true}, reg)) && false;});
                result.data.updates.filter(function (update) {
                    var simple = typeof update === 'string', promise, request;
                    if (!simple && (promise = (request = api.outstanding_requests[update.id]) && request.promise)) {
                        promise.deferred.resolve({
                            error: false, data: null, meta: {id: update.message.split('/').pop()}, promise: promise.id
                        });
                        delete api.outstanding_requests[promise.id];
                    }
                    return simple;
                }).forEach(function (update) {
                    var lcv, len = api.registrations.length, reg;
                    for (lcv = 0; lcv < len; lcv += 1)
                        if ((reg = api.registrations[lcv]) && reg.url === update)
                            (api.registrations[lcv] = null), reg.update(reg);
                    api.registrations = api.registrations.filter(Boolean);
                });
            })(true, null); // there are no registrations when subscribe() is called unless the connection's been reset
            (listen = function () {
                api.updates.get({handler: function (result) {
                    if (result.error) {
                        if (!api.disconnected) (api.disconnected = true), api.fire('disconnect'), (api.id = null);
                        warn(api.name + ': subscription failed\n', result.message);
                        return setTimeout(subscribe, RESUBSCRIBE);
                    }
                    if (!result.data || !result.data.updates.length) return setTimeout(listen, common.INSTANT);
                    fire_updates(false, result);
                    setTimeout(listen, common.INSTANT);
                }});
            })();
        }});
    }
{'fraction_non_alphanumeric': 0.1161217587373168, 'fraction_numerical': 0.003945885005636978, 'mean_word_length': 1.4188820722563054, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7394314', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1713, 'n_words': 413}