<commit_before><?php
/**
 * Created by IntelliJ IDEA.
 * User: leng
 * Date: 11/03/2017
 * Time: 10:43 PM
 */

/**
 * An implementation of the Promise pattern based on Sabre event promise.
 * Modified to used with Vertx and DooJ framework which runs on JVM
 *
 * A promise represents the result of an asynchronous operation.
 * At any given point a promise can be in one of three states:
 *
 * 1. Pending (the promise does not have a result yet).
 * 2. Fulfilled (the asynchronous operation has completed with a result).
 * 3. Rejected (the asynchronous operation has completed with an error).
 * 4. Start (first call of promise to start the call)
 *
 * Usage
 *
 * # Repeat a the same async call X times based on an array of values
 *        $this->resultArr = [];
 *        $this->errorHandler = function ($error, $promise) {
 *            $this->app->logDebug('PROMISE ERROR');
 *            $promise->reject($error);
 *            $this->sendError($error);
 *        };
 *
 *        \DooPromise::repeat($ids, [
 *            //on each promise, doing the same thing based on the Array of parameters passed in
 *            'then' => function ($param, $result, $nextPromise) {
 *                $id = $param;
 *                if (!\is_bool($result)) {
 *                    $this->resultArr[] = $result;
 *                }
 *
 *                $this->serviceCall('getCatalogItemDetails', $id, function($result) use ($id, $nextPromise) {
 *                    $this->app->logDebug('Fulfill ' . $id);
 *                    $nextPromise->fulfill($result);
 *                }, $this->defaultErrorHandler($this->errorHandler, $nextPromise, true, true));
 *            },
 *
 *            //just logging the reason where the promise failed (here is only bcoz of DB error)
 *            'otherwise' => function($reason) {
 *                $this->app->logDebug('otherwise');
 *                $this->app->logDebug($reason);
 *                $this->app->trace($reason);
 *            },
 *
 *            //final last call on the list of repeat promise, should now return result to client
 *            'final' => function ($result) {
 *                $this->resultArr[] = $result;
 *                $this->app->logDebug('LAST THEN');
 *                $this->sendResult($this->resultArr);
 *            }
 *        ]);
 *
 *        # ------- 2nd type of Promise usage, using a for loop -----
 *        $promise = new Promise();
 *        $subPromise = null;
 *
 *        $this->errorHandler = function ($error, $promise) {
 *            $this->app->logDebug('PROMISE ERROR');
 *            $promise->reject($error);
 *            $this->sendError($error);
 *        };
 *
 *        foreach ($ids as $id) {
 *            $p = ($subPromise) ? $subPromise : $promise;
 *
 *            $subPromise = $p->then(function($result) use ($id, $promise) {
 *                if (!\is_bool($result)) {
 *                    $this->resultArr[] = $result;
 *                }
 *
 *                $nextPromise = new Promise();
 *                $this->serviceCall('getCatalogItemDetails', $id, function($result) use ($nextPromise) {
 *                    $this->app->logDebug('Fulfill');
 *                    $nextPromise->fulfill($result);
 *                }, $this->defaultErrorHandler($this->errorHandler, $nextPromise , true, true));
 *
 *                return $nextPromise;
 *            })
 *            ->otherwise(function($reason) {
 *                $this->app->logDebug('otherwise');
 *                $this->app->logDebug($reason);
 *                $this->app->trace($reason);
 *            });
 *        }
 *
 *        //last
 *        $subPromise->then(function($result) {
 *            $this->resultArr[] = $result;
 *            $this->app->logDebug('LAST THEN');
 *            $this->sendResult($this->resultArr);
 *        });
 *
 *        $promise->start(true);
 *
 *
 *        # 3rd type, most common usage, $promise->then()->then()->then(); and call $promise->start() to start()
 *        $promise->then(function($firstPromise) use ($ids) {
 *            $this->app->logDebug('CALL 1');
 *
 *            $this->serviceCall('getCatalogItemDetails', $ids[0], function($result) use ($firstPromise) {
 *                $this->app->logDebug('Fulfill 1');
 *                $firstPromise->fulfill($result);
 *            }, $this->defaultErrorHandler());
 *
 *            return $firstPromise;
 *        })
 *        ->then(function($result) use ($ids) {
 *
 *            $nextPromise = new Promise();
 *            $this->resultArr[] = $result;
 *            $this->app->logDebug('CALL 2');
 *
 *            $this->serviceCall('getCatalogItemDetails', $ids[1], function($result) use ($nextPromise) {
 *                $this->app->logDebug('Fulfill 2');
 *                $nextPromise->fulfill($result);
 *            }, $this->defaultErrorHandler());
 *
 *            return $nextPromise;
 *        })
 *        ->then(function($result) {
 *            $this->resultArr[] = $result;
 *            $this->app->logDebug('LAST THEN NOW FINAL ' . \sizeof($this->resultArr));
 *            $this->sendResult($this->resultArr);
 *        });
 *
 *        $promise->start();
 */
class DooPromise
{
    /**
     * The asynchronous operation is pending.
     */
    const PENDING = 0;
    /**
     * The asynchronous operation has completed, and has a result.
     */
    const FULFILLED = 1;<commit_msg>Update promise class comment block<commit_after><?php
/**
 * Created by IntelliJ IDEA.
 * User: leng
 * Date: 11/03/2017
 * Time: 10:43 PM
 */

/**
 * An implementation of the Promise pattern based on Sabre event promise.
 * Modified to used with Vertx and DooJ framework which runs on JVM
 *
 * A promise represents the result of an asynchronous operation.
 * At any given point a promise can be in one of three states:
 *
 * 1. Pending (the promise does not have a result yet).
 * 2. Fulfilled (the asynchronous operation has completed with a result).
 * 3. Rejected (the asynchronous operation has completed with an error).
 * 4. Start (first call of promise to start the call)
 *
 * Usage
 *
 * # Repeat a the same async call X times based on an array of values
 *        $this->resultArr = [];
 *        $this->errorHandler = function ($error, $promise) {
 *            $this->app->logDebug('PROMISE ERROR');
 *            $promise->reject($error);
 *            $this->sendError($error);
 *        };
 *
 *        \DooPromise::repeat($ids, [
 *            //on each promise, doing the same thing based on the Array of parameters passed in
 *            'then' => function ($param, $result, $nextPromise) {
 *                $id = $param;
 *                if (!\is_bool($result)) {
 *                    $this->resultArr[] = $result;
 *                }
 *
 *                $this->serviceCall('getCatalogItemDetails', $id, function($result) use ($id, $nextPromise) {
 *                    $this->app->logDebug('Fulfill ' . $id);
 *                    $nextPromise->fulfill($result);
 *                }, $this->defaultErrorHandler($this->errorHandler, $nextPromise, true, true));
 *            },
 *
 *            //just logging the reason where the promise failed (here is only bcoz of DB error)
 *            'otherwise' => function($reason) {
 *                $this->app->logDebug('otherwise');
 *                $this->app->logDebug($reason);
 *                $this->app->trace($reason);
 *            },
 *
 *            //final last call on the list of repeat promise, should now return result to client
 *            'final' => function ($result) {
 *                $this->resultArr[] = $result;
 *                $this->app->logDebug('LAST THEN');
 *                $this->sendResult($this->resultArr);
 *            }
 *        ]);
 *
 *        # ------- 2nd type of Promise usage, using a for loop -----
 *        $promise = new DooPromise();
 *        $subPromise = null;
 *
 *        $this->errorHandler = function ($error, $promise) {
 *            $this->app->logDebug('PROMISE ERROR');
 *            $promise->reject($error);
 *            $this->sendError($error);
 *        };
 *
 *        foreach ($ids as $id) {
 *            $p = ($subPromise) ? $subPromise : $promise;
 *
 *            $subPromise = $p->then(function($result) use ($id, $promise) {
 *                if (!\is_bool($result)) {
 *                    $this->resultArr[] = $result;
 *                }
 *
 *                $nextPromise = new Promise();
 *                $this->serviceCall('getCatalogItemDetails', $id, function($result) use ($nextPromise) {
 *                    $this->app->logDebug('Fulfill');
 *                    $nextPromise->fulfill($result);
 *                }, $this->defaultErrorHandler($this->errorHandler, $nextPromise , true, true));
 *
 *                return $nextPromise;
 *            })
 *            ->otherwise(function($reason) {
 *                $this->app->logDebug('otherwise');
 *                $this->app->logDebug($reason);
 *                $this->app->trace($reason);
 *            });
 *        }
 *
 *        //last
 *        $subPromise->then(function($result) {
 *            $this->resultArr[] = $result;
 *            $this->app->logDebug('LAST THEN');
 *            $this->sendResult($this->resultArr);
 *        });
 *
 *        $promise->start(true);
 *
 *
 *        # 3rd type, most common usage, $promise->then()->then()->then(); and call $promise->start() to start()
 *        $promise->then(function($firstPromise) use ($ids) {
 *            $this->app->logDebug('CALL 1');
 *
 *            $this->serviceCall('getCatalogItemDetails', $ids[0], function($result) use ($firstPromise) {
 *                $this->app->logDebug('Fulfill 1');
 *                $firstPromise->fulfill($result);
 *            }, $this->defaultErrorHandler());
 *
 *            return $firstPromise;
 *        })
 *        ->then(function($result) use ($ids) {
 *
 *            $nextPromise = new DooPromise();
 *            $this->resultArr[] = $result;
 *            $this->app->logDebug('CALL 2');
 *
 *            $this->serviceCall('getCatalogItemDetails', $ids[1], function($result) use ($nextPromise) {
 *                $this->app->logDebug('Fulfill 2');
 *                $nextPromise->fulfill($result);
 *            }, $this->defaultErrorHandler());
 *
 *            return $nextPromise;
 *        })
 *        ->then(function($result) {
 *            $this->resultArr[] = $result;
 *            $this->app->logDebug('LAST THEN NOW FINAL ' . \sizeof($this->resultArr));
 *            $this->sendResult($this->resultArr);
 *        });
 *
 *        $promise->start();
 */
class DooPromise
{
    /**
     * The asynchronous operation is pending.
     */
    const PENDING = 0;
    /**
     * The asynchronous operation has completed, and has a result.
     */
    const FULFILLED = 1;
{'fraction_non_alphanumeric': 0.16369515011547345, 'fraction_numerical': 0.004803695150115473, 'mean_word_length': 1.8542051146849459, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 169, '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': '6201389', 'n_tokens_mistral': 3123, 'n_tokens_neox': 2975, 'n_words': 705}