<commit_before>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/

/**********************************************************\
 *                                                        *
 * Future.js                                              *
 *                                                        *
 * hprose Future for HTML5.                               *
 *                                                        *
 * LastModified: Jun 25, 2015                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

(function (global) {
    'use strict';

    var PENDING = 0;
    var FULFILLED = 1;
    var REJECTED = 2;

    var setImmediate = global.setImmediate || function(f) { setTimeout(f, 0); };

    function Future(computation) {
        if (typeof computation === "function") {
            var completer = new Completer();
            setImmediate(function() {
                try {
                    completer.complete(computation());
                }
                catch(e) {
                    completer.completeError(e);
                }
            });
            return completer.future;
        }
    }

    function delayed(duration, computation) {
        if (computation === undefined) {
            computation = function() { return null; };
        }
        var completer = new Completer();
        global.setTimeout(function() {
            try {
                completer.complete(computation());
            }
            catch(e) {
                completer.completeError(e);
            }
        }, duration);
        return completer.future;
    }

    function error(e) {
        var completer = new Completer();
        completer.completeError(e);
        return completer.future;
    }

    function sync(computation) {
        var completer = new Completer(true);
        try {
            completer.complete(computation());
        }
        catch(e) {
            completer.completeError(e);
        }
        return completer.future;
    }

    function value(v) {
        return sync(function() { return v; });
    }

    Object.defineProperties(Future, {
        delayed: { value: delayed },
        error: { value: error },
        sync: { value : sync },
        value: { value : value }
    });

    global.hprose.Future = Future;

    function isFuture(obj) {
        return (obj instanceof Future) && (typeof (obj.then === "function"));
    }

    function Completer(sync) {
        var _status = PENDING;
        var _result;
        var _error;
        var _callbacks = [];
        var _future = new Future();
        var run = sync ?
            function(callback, x) {
                return Future.sync(function() { return callback(x); });
            } :
            function(callback, x) {
                return new Future(function() { return callback(x); });
            };

        function resolve(onComplete, onError, x) {
            if (isFuture(x)) {
                if (x === _future) {
                    throw new TypeError('Self resolution');
                }
                return x.then(onComplete, onError);
            }
            if ((typeof x === "object") || (typeof x === "function")) {
                var completer = new Completer();
                var then;
                try {
                    then = x.then;
                }
                catch (e) {
                    completer.completeError(e);
                    return completer.future;
                }
                if (typeof then === "function") {
                    try {
                        then.call(x, completer.complete, completer.completeError);
                    }
                    catch (e) {
                        completer.completeError(e);
                    }
                    return completer.future;
                }
            }
            if (onComplete) {
                return run(onComplete, x);
            }
            return x;
        }

        // Calling complete must not be done more than once.
        function complete(result) {
            if (_status === PENDING) {
                _status = FULFILLED;
                _result = result;
                while (_callbacks.length > 0) {
                    var callback = _callbacks.shift();
                    result = resolve(callback[0], callback[1], result);
                }
            }
        }

        // Calling complete must not be done more than once.
        function completeError(error) {
            if (_status === PENDING) {
                _status = REJECTED;
                _error = error;
                var callback;
                var result;
                while (_callbacks.length > 0) {
                    callback = _callbacks.shift();
                    if (callback[1]) {
                        result = run(callback[1], error);
                        break;
                    }
                }
                if (_callbacks.length > 0) {
                    while (_callbacks.length > 0) {
                        callback = _callbacks.shift();
                        result = resolve(callback[0], callback[1], result);
                    }
                }
            }
        }

        function then(onComplete, onError) {
            if (typeof onComplete !== "function") onComplete = null;
            if (typeof onError !== "function") onError = null;
            if (onComplete || onError) {
                if (onComplete && (_status === FULFILLED)) {
                     return resolve(onComplete, onError, _result);
                }
                if (onError && (_status === REJECTED)) {
                    return run(onError, _error);
                }
                _callbacks.push([onComplete, onError]);
            }
            return _future;
        }<commit_msg>while changed to do ... while.<commit_after>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/

/**********************************************************\
 *                                                        *
 * Future.js                                              *
 *                                                        *
 * hprose Future for HTML5.                               *
 *                                                        *
 * LastModified: Jun 25, 2015                             *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

(function (global) {
    'use strict';

    var PENDING = 0;
    var FULFILLED = 1;
    var REJECTED = 2;

    var setImmediate = global.setImmediate || function(f) { setTimeout(f, 0); };

    function Future(computation) {
        if (typeof computation === "function") {
            var completer = new Completer();
            setImmediate(function() {
                try {
                    completer.complete(computation());
                }
                catch(e) {
                    completer.completeError(e);
                }
            });
            return completer.future;
        }
    }

    function delayed(duration, computation) {
        if (computation === undefined) {
            computation = function() { return null; };
        }
        var completer = new Completer();
        global.setTimeout(function() {
            try {
                completer.complete(computation());
            }
            catch(e) {
                completer.completeError(e);
            }
        }, duration);
        return completer.future;
    }

    function error(e) {
        var completer = new Completer();
        completer.completeError(e);
        return completer.future;
    }

    function sync(computation) {
        var completer = new Completer(true);
        try {
            completer.complete(computation());
        }
        catch(e) {
            completer.completeError(e);
        }
        return completer.future;
    }

    function value(v) {
        return sync(function() { return v; });
    }

    Object.defineProperties(Future, {
        delayed: { value: delayed },
        error: { value: error },
        sync: { value : sync },
        value: { value : value }
    });

    global.hprose.Future = Future;

    function isFuture(obj) {
        return (obj instanceof Future) && (typeof (obj.then === "function"));
    }

    function Completer(sync) {
        var _status = PENDING;
        var _result;
        var _error;
        var _callbacks = [];
        var _future = new Future();
        var run = sync ?
            function(callback, x) {
                return Future.sync(function() { return callback(x); });
            } :
            function(callback, x) {
                return new Future(function() { return callback(x); });
            };

        function resolve(onComplete, onError, x) {
            if (isFuture(x)) {
                if (x === _future) {
                    throw new TypeError('Self resolution');
                }
                return x.then(onComplete, onError);
            }
            if ((typeof x === "object") || (typeof x === "function")) {
                var completer = new Completer();
                var then;
                try {
                    then = x.then;
                }
                catch (e) {
                    completer.completeError(e);
                    return completer.future;
                }
                if (typeof then === "function") {
                    try {
                        then.call(x, completer.complete, completer.completeError);
                    }
                    catch (e) {
                        completer.completeError(e);
                    }
                    return completer.future;
                }
            }
            if (onComplete) {
                return run(onComplete, x);
            }
            return x;
        }

        // Calling complete must not be done more than once.
        function complete(result) {
            if (_status === PENDING) {
                _status = FULFILLED;
                _result = result;
                while (_callbacks.length > 0) {
                    var callback = _callbacks.shift();
                    result = resolve(callback[0], callback[1], result);
                }
            }
        }

        // Calling complete must not be done more than once.
        function completeError(error) {
            if (_status === PENDING) {
                _status = REJECTED;
                _error = error;
                var callback;
                var result;
                while (_callbacks.length > 0) {
                    callback = _callbacks.shift();
                    if (callback[1]) {
                        result = run(callback[1], error);
                        break;
                    }
                }
                if (_callbacks.length > 0) {
                    do {
                        callback = _callbacks.shift();
                        result = resolve(callback[0], callback[1], result);
                    } while (_callbacks.length > 0);
                }
            }
        }

        function then(onComplete, onError) {
            if (typeof onComplete !== "function") onComplete = null;
            if (typeof onError !== "function") onError = null;
            if (onComplete || onError) {
                if (onComplete && (_status === FULFILLED)) {
                     return resolve(onComplete, onError, _result);
                }
                if (onError && (_status === REJECTED)) {
                    return run(onError, _error);
                }
                _callbacks.push([onComplete, onError]);
            }
            return _future;
        }
{'fraction_non_alphanumeric': 0.13338027067198624, 'fraction_numerical': 0.0032856137057028865, 'mean_word_length': 1.0457673227716435, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860980', 'n_tokens_mistral': 3055, 'n_tokens_neox': 2843, 'n_words': 655}