Update Files

This commit is contained in:
2025-01-22 16:18:30 +01:00
parent ed4603cf95
commit a36294b518
16718 changed files with 2960346 additions and 0 deletions

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Dirk-Jan Wassink
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,120 @@
# Promise-parallel-throttle
[![Build Status](https://travis-ci.org/DJWassink/Promise-parallel-throttle.svg?branch=master)](https://travis-ci.org/DJWassink/Promise-parallel-throttle)
Run a array of Promises in parallel. Kinda like Promise.all(), but throttled!
## Install
### NPM
```bash
npm i promise-parallel-throttle -S
```
### Yarn
```bash
yarn add promise-parallel-throttle
```
## Usage
```js
import Throttle from 'promise-parallel-throttle';
//Function which should return a Promise
const doReq = async (firstName, lastName) => {
//Do something async.
return firstName + " " + lastName;
}
const users = [
{firstName: "Irene", lastName: "Pullman"},
{firstName: "Sean", lastName: "Parr"}
];
//Queue with functions to be run
const queue = users.map(user => () => doReq(user.firstName, user.lastName));
//Default Throttle runs with 5 promises parallel.
const formattedNames = await Throttle.all(queue);
console.log(formattedNames); //['Irene Pullman', 'Sean Parr']
```
## API
### Throttle.all
`Throttle.all(tasks, options)`
Throttle.all is made to behave exactly like Promise.all but instead of all the tasks running in parallel it runs a maxium amount of tasks in parallel.
Only the tasks parameter is required while the [options](#options-object) parameter is optional.
### Throttle.sync
`Throttle.sync(tasks, options)`
Throttle.sync runs all the tasks synchronously.
Once again the tasks array is required, the [options](#options-object) are optional.
Be aware that this method is simply a wrapper to pass `maxInProgress` with 1. So overwriting this option in the options object would run the tasks again in parallel.
### Throttle.raw
`Throttle.raw(tasks, options)`
The raw method instead of returning the tasks their results, will return a [result](#result-object--progress-callback) object.
Useful if you wan't more statistics about the execution of your tasks. Once again the tasks are required while the [options](#options-object) are optional.
#### Option's Object
|Parameter|Type|Default|Definition|
|:---|:---|:---|:---|
|maxInProgress |Integer|5| max amount of parallel threads|
|failFast |Boolean|true (false for the [raw](#throttleraw) method)| reject after a single error, or keep running|
|progressCallback |Function|Optional| callback with progress reports|
|nextCheck |Function|Optional| function which should return a promise, if the promise resolved true the next task is spawn, errors will propagate and should be handled in the calling code|
#### Result object / Progress callback
The `progressCallback` and the `Raw` will return a `Result` object with the following properties:
|Property|Type|Start value|Definition|
|:---|:---|:---|:---|
|amountDone|Integer|0|amount of tasks which are finished|
|amountStarted|Integer|0|amount of tasks which started|
|amountResolved|Integer|0|amount of tasks which successfully resolved|
|amountRejected|Integer|0|amount of tasks which returned in an error and are aborted|
|amountNextCheckFalsey|Integer|0|amount of tasks which got a falsey value in the [nextCheck](#nextcheck)|
|rejectedIndexes|Array|[]|all the indexes in the tasks array where the promise rejected|
|resolvedIndexes|Array|[]|all the indexes in the tasks array where the promise resolved|
|nextCheckFalseyIndexes|Array|[]|all the indexes in the tasks array where the [nextCheck](#nextcheck) returned a falsey value|
|taskResults|Array|[]|array containing the result of every task|
#### nextCheck
All the `Throttle` methods have a `nextCheck` method which will be used to verify if a next task is allowed to start.
The default `nextCheck` is defined like this;
```js
const defaultNextTaskCheck = (status, tasks) => {
return new Promise((resolve, reject) => {
resolve(status.amountStarted < tasks.length);
});
}
```
This function will get a status object as parameter which adheres to the [Result object](#result-object--progress-callback) and it also receives the list of tasks.
In the default `nextCheck` we simply check if the amount of started exceeds the amount to be done, if not we are free to start an other task.
This function can be useful to write your own scheduler based on, for example ram/cpu usage.
Lets say that your tasks use a lot of ram and you don't want to exceed a certain amount.
You could then write logic inside a `nextCheck` function which resolves after there is enough ram available to start the next task.
If a custom implementation decides to reject, the error is propagated and should be handled in the user it's code. If a custom implementation returns a falsey value the task will simply not execute and the next task will be scheduled.
## Example
Check out the example's directory, it's heavily documented so it should be easy to follow.
To run the example, at least Node 8.x.x is required, since it supports native async/await.
Simply run the example with npm:
```
npm run-script names
```
Or with Yarn:
```
yarn names
```

View File

@ -0,0 +1,41 @@
export interface Result<T> {
amountDone: number;
amountStarted: number;
amountResolved: number;
amountRejected: number;
amountNextCheckFalsey: number;
rejectedIndexes: number[];
resolvedIndexes: number[];
nextCheckFalseyIndexes: number[];
taskResults: T[];
}
export interface Options {
maxInProgress?: number;
failFast?: boolean;
progressCallback?: <T>(result: Result<T>) => void;
nextCheck?: nextTaskCheck;
}
export declare type Task<T> = () => Promise<T>;
export declare type Tasks<T> = Array<Task<T>>;
export declare type nextTaskCheck = <T>(status: Result<T>, tasks: Tasks<T>) => Promise<boolean>;
/**
* Raw throttle function, which can return extra meta data.
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export declare function raw<T>(tasks: Tasks<T>, options?: Options): Promise<Result<T>>;
/**
* Simply run all the promises after each other, so in synchronous manner
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export declare function sync<T>(tasks: Tasks<T>, options?: Options): Promise<T[]>;
/**
* Exposes the same behaviour as Promise.All(), but throttled!
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export declare function all<T>(tasks: Tasks<T>, options?: Options): Promise<T[]>;

View File

@ -0,0 +1,155 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var DEFAULT_MAX = 5;
/**
* Default checker which validates if a next task should begin.
* This can be overwritten to write own checks for example checking the amount
* of used ram and waiting till the ram is low enough for a next task.
*
* It should always resolve with a boolean, either `true` to start a next task
* or `false` to stop executing a new task.
*
* If this method rejects, the error will propagate to the caller
* @param status
* @param tasks
* @returns {Promise}
*/
var defaultNextTaskCheck = function (status, tasks) {
return new Promise(function (resolve, reject) {
resolve(status.amountStarted < tasks.length);
});
};
var DEFAULT_OPTIONS = {
maxInProgress: DEFAULT_MAX,
failFast: false,
nextCheck: defaultNextTaskCheck
};
/**
* Raw throttle function, which can return extra meta data.
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
function raw(tasks, options) {
return new Promise(function (resolve, reject) {
var myOptions = Object.assign({}, DEFAULT_OPTIONS, options);
var result = {
amountDone: 0,
amountStarted: 0,
amountResolved: 0,
amountRejected: 0,
amountNextCheckFalsey: 0,
rejectedIndexes: [],
resolvedIndexes: [],
nextCheckFalseyIndexes: [],
taskResults: []
};
if (tasks.length === 0) {
return resolve(result);
}
var failedFast = false;
var currentTaskIndex = 0;
var executeTask = function (index) {
result.amountStarted++;
if (typeof tasks[index] === 'function') {
tasks[index]().then(function (taskResult) {
result.taskResults[index] = taskResult;
result.resolvedIndexes.push(index);
result.amountResolved++;
taskDone();
}, function (error) {
result.taskResults[index] = error;
result.rejectedIndexes.push(index);
result.amountRejected++;
if (myOptions.failFast === true) {
failedFast = true;
return reject(result);
}
taskDone();
});
}
else {
failedFast = true;
return reject(new Error('tasks[' + index + ']: ' + tasks[index] + ', is supposed to be of type function'));
}
};
var taskDone = function () {
//make sure no more tasks are spawned when we failedFast
if (failedFast === true) {
return;
}
result.amountDone++;
if (typeof myOptions.progressCallback === 'function') {
myOptions.progressCallback(result);
}
if (result.amountDone === tasks.length) {
return resolve(result);
}
if (currentTaskIndex < tasks.length) {
nextTask(currentTaskIndex++);
}
};
var nextTask = function (index) {
//check if we can execute the next task
myOptions.nextCheck(result, tasks).then(function (canExecuteNextTask) {
if (canExecuteNextTask === true) {
//execute it
executeTask(index);
}
else {
result.amountNextCheckFalsey++;
result.nextCheckFalseyIndexes.push(index);
taskDone();
}
}, reject);
};
//spawn the first X task
for (var i = 0; i < Math.min(myOptions.maxInProgress, tasks.length); i++) {
nextTask(currentTaskIndex++);
}
});
}
exports.raw = raw;
/**
* Executes the raw function, but only return the task array
* @param tasks
* @param options
* @returns {Promise}
*/
function executeRaw(tasks, options) {
return new Promise(function (resolve, reject) {
raw(tasks, options).then(function (result) {
resolve(result.taskResults);
}, function (error) {
if (error instanceof Error) {
reject(error);
}
else {
reject(error.taskResults[error.rejectedIndexes[0]]);
}
});
});
}
/**
* Simply run all the promises after each other, so in synchronous manner
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
function sync(tasks, options) {
var myOptions = Object.assign({}, { maxInProgress: 1, failFast: true }, options);
return executeRaw(tasks, myOptions);
}
exports.sync = sync;
/**
* Exposes the same behaviour as Promise.All(), but throttled!
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
function all(tasks, options) {
var myOptions = Object.assign({}, { failFast: true }, options);
return executeRaw(tasks, myOptions);
}
exports.all = all;
//# sourceMappingURL=throttle.js.map

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1510840191396" clover="3.2.0">
<project timestamp="1510840191397" name="All files">
<metrics statements="63" coveredstatements="63" conditionals="18" coveredconditionals="18" methods="16" coveredmethods="16" elements="97" coveredelements="97" complexity="0" loc="63" ncloc="63" packages="1" files="1" classes="1">
<file name="throttle.ts" path="/mnt/d/Projecten/Promise-parallel-throttle/src/throttle.ts">
<metrics statements="63" coveredstatements="63" conditionals="18" coveredconditionals="18" methods="16" coveredmethods="16"/>
<line num="1" count="1" type="stmt"/>
<line num="2" count="1" type="stmt"/>
<line num="3" count="1" type="stmt"/>
<line num="17" count="1" type="stmt"/>
<line num="18" count="71" type="stmt"/>
<line num="19" count="71" type="stmt"/>
<line num="22" count="1" type="stmt"/>
<line num="34" count="19" type="stmt"/>
<line num="35" count="19" type="stmt"/>
<line num="36" count="19" type="stmt"/>
<line num="47" count="19" type="cond" truecount="2" falsecount="0"/>
<line num="48" count="1" type="stmt"/>
<line num="50" count="18" type="stmt"/>
<line num="51" count="18" type="stmt"/>
<line num="52" count="18" type="stmt"/>
<line num="53" count="81" type="stmt"/>
<line num="54" count="81" type="cond" truecount="2" falsecount="0"/>
<line num="55" count="78" type="stmt"/>
<line num="56" count="56" type="stmt"/>
<line num="57" count="56" type="stmt"/>
<line num="58" count="56" type="stmt"/>
<line num="59" count="56" type="stmt"/>
<line num="61" count="22" type="stmt"/>
<line num="62" count="22" type="stmt"/>
<line num="63" count="22" type="stmt"/>
<line num="64" count="22" type="cond" truecount="2" falsecount="0"/>
<line num="65" count="7" type="stmt"/>
<line num="66" count="7" type="stmt"/>
<line num="68" count="15" type="stmt"/>
<line num="72" count="3" type="stmt"/>
<line num="73" count="3" type="stmt"/>
<line num="76" count="18" type="stmt"/>
<line num="78" count="75" type="cond" truecount="2" falsecount="0"/>
<line num="79" count="8" type="stmt"/>
<line num="81" count="67" type="stmt"/>
<line num="82" count="67" type="cond" truecount="2" falsecount="0"/>
<line num="83" count="5" type="stmt"/>
<line num="85" count="67" type="cond" truecount="2" falsecount="0"/>
<line num="86" count="11" type="stmt"/>
<line num="88" count="56" type="cond" truecount="2" falsecount="0"/>
<line num="89" count="26" type="stmt"/>
<line num="92" count="18" type="stmt"/>
<line num="94" count="86" type="stmt"/>
<line num="95" count="85" type="cond" truecount="2" falsecount="0"/>
<line num="97" count="81" type="stmt"/>
<line num="100" count="4" type="stmt"/>
<line num="101" count="4" type="stmt"/>
<line num="102" count="4" type="stmt"/>
<line num="107" count="18" type="stmt"/>
<line num="108" count="60" type="stmt"/>
<line num="112" count="1" type="stmt"/>
<line num="120" count="8" type="stmt"/>
<line num="121" count="8" type="stmt"/>
<line num="122" count="4" type="stmt"/>
<line num="124" count="4" type="cond" truecount="2" falsecount="0"/>
<line num="125" count="2" type="stmt"/>
<line num="128" count="2" type="stmt"/>
<line num="140" count="4" type="stmt"/>
<line num="141" count="4" type="stmt"/>
<line num="143" count="1" type="stmt"/>
<line num="151" count="4" type="stmt"/>
<line num="152" count="4" type="stmt"/>
<line num="154" count="1" type="stmt"/>
</file>
</metrics>
</project>
</coverage>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,212 @@
body, html {
margin:0; padding: 0;
height: 100%;
}
body {
font-family: Helvetica Neue, Helvetica, Arial;
font-size: 14px;
color:#333;
}
.small { font-size: 12px; }
*, *:after, *:before {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
h1 { font-size: 20px; margin: 0;}
h2 { font-size: 14px; }
pre {
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
margin: 0;
padding: 0;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
a { color:#0074D9; text-decoration:none; }
a:hover { text-decoration:underline; }
.strong { font-weight: bold; }
.space-top1 { padding: 10px 0 0 0; }
.pad2y { padding: 20px 0; }
.pad1y { padding: 10px 0; }
.pad2x { padding: 0 20px; }
.pad2 { padding: 20px; }
.pad1 { padding: 10px; }
.space-left2 { padding-left:55px; }
.space-right2 { padding-right:20px; }
.center { text-align:center; }
.clearfix { display:block; }
.clearfix:after {
content:'';
display:block;
height:0;
clear:both;
visibility:hidden;
}
.fl { float: left; }
@media only screen and (max-width:640px) {
.col3 { width:100%; max-width:100%; }
.hide-mobile { display:none!important; }
}
.quiet {
color: #7f7f7f;
color: rgba(0,0,0,0.5);
}
.quiet a { opacity: 0.7; }
.fraction {
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-size: 10px;
color: #555;
background: #E8E8E8;
padding: 4px 5px;
border-radius: 3px;
vertical-align: middle;
}
div.path a:link, div.path a:visited { color: #333; }
table.coverage {
border-collapse: collapse;
margin: 10px 0 0 0;
padding: 0;
}
table.coverage td {
margin: 0;
padding: 0;
vertical-align: top;
}
table.coverage td.line-count {
text-align: right;
padding: 0 5px 0 20px;
}
table.coverage td.line-coverage {
text-align: right;
padding-right: 10px;
min-width:20px;
}
table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 100%;
}
.missing-if-branch {
display: inline-block;
margin-right: 5px;
border-radius: 3px;
position: relative;
padding: 0 4px;
background: #333;
color: yellow;
}
.skip-if-branch {
display: none;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: #ccc;
color: white;
}
.missing-if-branch .typ, .skip-if-branch .typ {
color: inherit !important;
}
.coverage-summary {
border-collapse: collapse;
width: 100%;
}
.coverage-summary tr { border-bottom: 1px solid #bbb; }
.keyline-all { border: 1px solid #ddd; }
.coverage-summary td, .coverage-summary th { padding: 10px; }
.coverage-summary tbody { border: 1px solid #bbb; }
.coverage-summary td { border-right: 1px solid #bbb; }
.coverage-summary td:last-child { border-right: none; }
.coverage-summary th {
text-align: left;
font-weight: normal;
white-space: nowrap;
}
.coverage-summary th.file { border-right: none !important; }
.coverage-summary th.pct { }
.coverage-summary th.pic,
.coverage-summary th.abs,
.coverage-summary td.pct,
.coverage-summary td.abs { text-align: right; }
.coverage-summary td.file { white-space: nowrap; }
.coverage-summary td.pic { min-width: 120px !important; }
.coverage-summary tfoot td { }
.coverage-summary .sorter {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
}
.coverage-summary .sorted .sorter {
background-position: 0 -20px;
}
.coverage-summary .sorted-desc .sorter {
background-position: 0 -10px;
}
.status-line { height: 10px; }
/* dark red */
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
.low .chart { border:1px solid #C21F39 }
/* medium red */
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
/* light red */
.low, .cline-no { background:#FCE1E5 }
/* light green */
.high, .cline-yes { background:rgb(230,245,208) }
/* medium green */
.cstat-yes { background:rgb(161,215,106) }
/* dark green */
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
.high .chart { border:1px solid rgb(77,146,33) }
.medium .chart { border:1px solid #666; }
.medium .cover-fill { background: #666; }
.cbranch-no { background: yellow !important; color: #111; }
.cstat-skip { background: #ddd; color: #111; }
.fstat-skip { background: #ddd; color: #111 !important; }
.cbranch-skip { background: #ddd !important; color: #111; }
span.cline-neutral { background: #eaeaea; }
.medium { background: #eaeaea; }
.cover-fill, .cover-empty {
display:inline-block;
height: 12px;
}
.chart {
line-height: 0;
}
.cover-empty {
background: white;
}
.cover-full {
border-right: none !important;
}
pre.prettyprint {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.com { color: #999 !important; }
.ignore-none { color: #999; font-weight: normal; }
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -48px;
}
.footer, .push {
height: 48px;
}

View File

@ -0,0 +1,93 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for All files</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="prettify.css" />
<link rel="stylesheet" href="base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
All files
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>64/64</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>18/18</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>16/16</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>63/63</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<div class="pad1">
<table class="coverage-summary">
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="throttle.ts"><a href="throttle.ts.html">throttle.ts</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="64" class="abs high">64/64</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="18" class="abs high">18/18</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="16" class="abs high">16/16</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="63" class="abs high">63/63</td>
</tr>
</tbody>
</table>
</div><div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Nov 16 2017 14:49:51 GMT+0100 (STD)
</div>
</div>
<script src="prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="sorter.js"></script>
</body>
</html>

View File

@ -0,0 +1 @@
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

View File

@ -0,0 +1,158 @@
var addSorting = (function () {
"use strict";
var cols,
currentSort = {
index: 0,
desc: false
};
// returns the summary table element
function getTable() { return document.querySelector('.coverage-summary'); }
// returns the thead element of the summary table
function getTableHeader() { return getTable().querySelector('thead tr'); }
// returns the tbody element of the summary table
function getTableBody() { return getTable().querySelector('tbody'); }
// returns the th element for nth column
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }
// loads all columns
function loadColumns() {
var colNodes = getTableHeader().querySelectorAll('th'),
colNode,
cols = [],
col,
i;
for (i = 0; i < colNodes.length; i += 1) {
colNode = colNodes[i];
col = {
key: colNode.getAttribute('data-col'),
sortable: !colNode.getAttribute('data-nosort'),
type: colNode.getAttribute('data-type') || 'string'
};
cols.push(col);
if (col.sortable) {
col.defaultDescSort = col.type === 'number';
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
}
}
return cols;
}
// attaches a data attribute to every tr element with an object
// of data values keyed by column name
function loadRowData(tableRow) {
var tableCols = tableRow.querySelectorAll('td'),
colNode,
col,
data = {},
i,
val;
for (i = 0; i < tableCols.length; i += 1) {
colNode = tableCols[i];
col = cols[i];
val = colNode.getAttribute('data-value');
if (col.type === 'number') {
val = Number(val);
}
data[col.key] = val;
}
return data;
}
// loads all row data
function loadData() {
var rows = getTableBody().querySelectorAll('tr'),
i;
for (i = 0; i < rows.length; i += 1) {
rows[i].data = loadRowData(rows[i]);
}
}
// sorts the table using the data for the ith column
function sortByIndex(index, desc) {
var key = cols[index].key,
sorter = function (a, b) {
a = a.data[key];
b = b.data[key];
return a < b ? -1 : a > b ? 1 : 0;
},
finalSorter = sorter,
tableBody = document.querySelector('.coverage-summary tbody'),
rowNodes = tableBody.querySelectorAll('tr'),
rows = [],
i;
if (desc) {
finalSorter = function (a, b) {
return -1 * sorter(a, b);
};
}
for (i = 0; i < rowNodes.length; i += 1) {
rows.push(rowNodes[i]);
tableBody.removeChild(rowNodes[i]);
}
rows.sort(finalSorter);
for (i = 0; i < rows.length; i += 1) {
tableBody.appendChild(rows[i]);
}
}
// removes sort indicators for current column being sorted
function removeSortIndicators() {
var col = getNthColumn(currentSort.index),
cls = col.className;
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
col.className = cls;
}
// adds sort indicators for current column being sorted
function addSortIndicators() {
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
}
// adds event listeners for all sorter widgets
function enableUI() {
var i,
el,
ithSorter = function ithSorter(i) {
var col = cols[i];
return function () {
var desc = col.defaultDescSort;
if (currentSort.index === i) {
desc = !currentSort.desc;
}
sortByIndex(i, desc);
removeSortIndicators();
currentSort.index = i;
currentSort.desc = desc;
addSortIndicators();
};
};
for (i =0 ; i < cols.length; i += 1) {
if (cols[i].sortable) {
// add the click event handler on the th so users
// dont have to click on those tiny arrows
el = getNthColumn(i).querySelector('.sorter').parentElement;
if (el.addEventListener) {
el.addEventListener('click', ithSorter(i));
} else {
el.attachEvent('onclick', ithSorter(i));
}
}
}
}
// adds sorting functionality to the UI
return function () {
if (!getTable()) {
return;
}
cols = loadColumns();
loadData(cols);
addSortIndicators();
enableUI();
};
})();
window.addEventListener('load', addSorting);

View File

@ -0,0 +1,635 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for throttle.ts</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="prettify.css" />
<link rel="stylesheet" href="base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="index.html">All files</a> throttle.ts
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>64/64</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>18/18</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>16/16</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>63/63</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-yes">71x</span>
<span class="cline-any cline-yes">71x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">19x</span>
<span class="cline-any cline-yes">19x</span>
<span class="cline-any cline-yes">19x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">19x</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18x</span>
<span class="cline-any cline-yes">18x</span>
<span class="cline-any cline-yes">18x</span>
<span class="cline-any cline-yes">81x</span>
<span class="cline-any cline-yes">81x</span>
<span class="cline-any cline-yes">78x</span>
<span class="cline-any cline-yes">56x</span>
<span class="cline-any cline-yes">56x</span>
<span class="cline-any cline-yes">56x</span>
<span class="cline-any cline-yes">56x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">22x</span>
<span class="cline-any cline-yes">22x</span>
<span class="cline-any cline-yes">22x</span>
<span class="cline-any cline-yes">22x</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-yes">7x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">15x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-yes">3x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">75x</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">67x</span>
<span class="cline-any cline-yes">67x</span>
<span class="cline-any cline-yes">5x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">67x</span>
<span class="cline-any cline-yes">11x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">56x</span>
<span class="cline-any cline-yes">26x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">86x</span>
<span class="cline-any cline-yes">85x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">81x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18x</span>
<span class="cline-any cline-yes">60x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-yes">8x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-yes">4x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1x</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">const DEFAULT_MAX = 5;
&nbsp;
export interface Result&lt;T&gt; {
amountDone: number;
amountStarted: number;
amountResolved: number;
amountRejected: number;
amountNextCheckFalsey: number;
rejectedIndexes: number[];
resolvedIndexes: number[];
nextCheckFalseyIndexes: number[];
taskResults: T[];
}
&nbsp;
export interface Options {
maxInProgress?: number;
failFast?: boolean;
progressCallback?: &lt;T&gt;(result: Result&lt;T&gt;) =&gt; void;
nextCheck?: nextTaskCheck;
}
&nbsp;
/**
* Default checker which validates if a next task should begin.
* This can be overwritten to write own checks for example checking the amount
* of used ram and waiting till the ram is low enough for a next task.
*
* It should always resolve with a boolean, either `true` to start a next task
* or `false` to stop executing a new task.
*
* If this method rejects, the error will propagate to the caller
* @param status
* @param tasks
* @returns {Promise}
*/
const defaultNextTaskCheck: nextTaskCheck = &lt;T&gt;(status: Result&lt;T&gt;, tasks: Tasks&lt;T&gt;): Promise&lt;boolean&gt; =&gt; {
return new Promise((resolve, reject) =&gt; {
resolve(status.amountStarted &lt; tasks.length);
});
};
&nbsp;
const DEFAULT_OPTIONS = {
maxInProgress: DEFAULT_MAX,
failFast: false,
nextCheck: defaultNextTaskCheck
};
&nbsp;
export type Task&lt;T&gt; = () =&gt; Promise&lt;T&gt;;
export type Tasks&lt;T&gt; = Array&lt;Task&lt;T&gt;&gt;;
export type nextTaskCheck = &lt;T&gt;(status: Result&lt;T&gt;, tasks: Tasks&lt;T&gt;) =&gt; Promise&lt;boolean&gt;;
&nbsp;
/**
* Raw throttle function, which can return extra meta data.
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export function raw&lt;T&gt;(tasks: Tasks&lt;T&gt;, options?: Options): Promise&lt;Result&lt;T&gt;&gt; {
return new Promise((resolve, reject) =&gt; {
const myOptions = Object.assign({}, DEFAULT_OPTIONS, options);
const result: Result&lt;T&gt; = {
amountDone: 0,
amountStarted: 0,
amountResolved: 0,
amountRejected: 0,
amountNextCheckFalsey: 0,
rejectedIndexes: [],
resolvedIndexes: [],
nextCheckFalseyIndexes: [],
taskResults: []
};
&nbsp;
if (tasks.length === 0) {
return resolve(result);
}
&nbsp;
let failedFast = false;
let currentTaskIndex = 0;
const executeTask = (index: number) =&gt; {
result.amountStarted++;
&nbsp;
if (typeof tasks[index] === 'function') {
tasks[index]().then(
taskResult =&gt; {
result.taskResults[index] = taskResult;
result.resolvedIndexes.push(index);
result.amountResolved++;
taskDone();
},
error =&gt; {
result.taskResults[index] = error;
result.rejectedIndexes.push(index);
result.amountRejected++;
if (myOptions.failFast === true) {
failedFast = true;
return reject(result);
}
taskDone();
}
);
} else {
failedFast = true;
return reject(
new Error('tasks[' + index + ']: ' + tasks[index] + ', is supposed to be of type function')
);
}
};
&nbsp;
const taskDone = () =&gt; {
//make sure no more tasks are spawned when we failedFast
if (failedFast === true) {
return;
}
&nbsp;
result.amountDone++;
if (typeof (myOptions as Options).progressCallback === 'function') {
(myOptions as any).progressCallback(result);
}
if (result.amountDone === tasks.length) {
return resolve(result);
}
if (currentTaskIndex &lt; tasks.length) {
nextTask(currentTaskIndex++);
}
};
&nbsp;
const nextTask = (index: number) =&gt; {
//check if we can execute the next task
myOptions.nextCheck(result, tasks).then(canExecuteNextTask =&gt; {
if (canExecuteNextTask === true) {
//execute it
executeTask(index);
} else {
result.amountNextCheckFalsey++;
result.nextCheckFalseyIndexes.push(index);
taskDone();
}
}, reject);
};
&nbsp;
//spawn the first X task
for (let i = 0; i &lt; Math.min(myOptions.maxInProgress, tasks.length); i++) {
nextTask(currentTaskIndex++);
}
});
}
&nbsp;
/**
* Executes the raw function, but only return the task array
* @param tasks
* @param options
* @returns {Promise}
*/
function executeRaw&lt;T&gt;(tasks: Tasks&lt;T&gt;, options: Options): Promise&lt;T[]&gt; {
return new Promise((resolve, reject) =&gt; {
raw(tasks, options).then(
(result: Result&lt;T&gt;) =&gt; {
resolve(result.taskResults);
},
(error: Error | Result&lt;T&gt;) =&gt; {
if (error instanceof Error) {
reject(error);
} else {
reject(error.taskResults[error.rejectedIndexes[0]]);
}
}
);
});
}
&nbsp;
/**
* Simply run all the promises after each other, so in synchronous manner
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export function sync&lt;T&gt;(tasks: Tasks&lt;T&gt;, options?: Options): Promise&lt;T[]&gt; {
const myOptions = Object.assign({}, { maxInProgress: 1, failFast: true }, options);
return executeRaw(tasks, myOptions);
}
&nbsp;
/**
* Exposes the same behaviour as Promise.All(), but throttled!
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export function all&lt;T&gt;(tasks: Tasks&lt;T&gt;, options?: Options): Promise&lt;T[]&gt; {
const myOptions = Object.assign({}, { failFast: true }, options);
return executeRaw(tasks, myOptions);
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Thu Nov 16 2017 14:49:51 GMT+0100 (STD)
</div>
</div>
<script src="prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="sorter.js"></script>
</body>
</html>

View File

@ -0,0 +1,122 @@
TN:
SF:/mnt/d/Projecten/Promise-parallel-throttle/src/throttle.ts
FN:17,(anonymous_0)
FN:18,(anonymous_1)
FN:33,raw
FN:34,(anonymous_3)
FN:52,(anonymous_4)
FN:55,(anonymous_5)
FN:60,(anonymous_6)
FN:76,(anonymous_7)
FN:92,(anonymous_8)
FN:94,(anonymous_9)
FN:119,executeRaw
FN:120,(anonymous_11)
FN:121,(anonymous_12)
FN:123,(anonymous_13)
FN:139,sync
FN:150,all
FNF:16
FNH:16
FNDA:71,(anonymous_0)
FNDA:71,(anonymous_1)
FNDA:19,raw
FNDA:19,(anonymous_3)
FNDA:81,(anonymous_4)
FNDA:56,(anonymous_5)
FNDA:22,(anonymous_6)
FNDA:75,(anonymous_7)
FNDA:86,(anonymous_8)
FNDA:85,(anonymous_9)
FNDA:8,executeRaw
FNDA:8,(anonymous_11)
FNDA:4,(anonymous_12)
FNDA:4,(anonymous_13)
FNDA:4,sync
FNDA:4,all
DA:1,1
DA:2,1
DA:3,1
DA:17,1
DA:18,71
DA:19,71
DA:22,1
DA:34,19
DA:35,19
DA:36,19
DA:47,19
DA:48,1
DA:50,18
DA:51,18
DA:52,18
DA:53,81
DA:54,81
DA:55,78
DA:56,56
DA:57,56
DA:58,56
DA:59,56
DA:61,22
DA:62,22
DA:63,22
DA:64,22
DA:65,7
DA:66,7
DA:68,15
DA:72,3
DA:73,3
DA:76,18
DA:78,75
DA:79,8
DA:81,67
DA:82,67
DA:83,5
DA:85,67
DA:86,11
DA:88,56
DA:89,26
DA:92,18
DA:94,86
DA:95,85
DA:97,81
DA:100,4
DA:101,4
DA:102,4
DA:107,18
DA:108,60
DA:112,1
DA:120,8
DA:121,8
DA:122,4
DA:124,4
DA:125,2
DA:128,2
DA:140,4
DA:141,4
DA:143,1
DA:151,4
DA:152,4
DA:154,1
LF:63
LH:63
BRDA:47,0,0,1
BRDA:47,0,1,18
BRDA:54,1,0,78
BRDA:54,1,1,3
BRDA:64,2,0,7
BRDA:64,2,1,15
BRDA:78,3,0,8
BRDA:78,3,1,67
BRDA:82,4,0,5
BRDA:82,4,1,62
BRDA:85,5,0,11
BRDA:85,5,1,56
BRDA:88,6,0,26
BRDA:88,6,1,30
BRDA:95,7,0,81
BRDA:95,7,1,4
BRDA:124,8,0,2
BRDA:124,8,1,2
BRF:18
BRH:18
end_of_record

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,8 @@
--------------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
--------------|----------|----------|----------|----------|----------------|
src/  | 100 | 100 | 100 | 100 |  |
throttle.ts | 100 | 100 | 100 | 100 |  |
--------------|----------|----------|----------|----------|----------------|
All files  | 100 | 100 | 100 | 100 |  |
--------------|----------|----------|----------|----------|----------------|

View File

@ -0,0 +1,213 @@
body, html {
margin:0; padding: 0;
height: 100%;
}
body {
font-family: Helvetica Neue, Helvetica, Arial;
font-size: 14px;
color:#333;
}
.small { font-size: 12px; }
*, *:after, *:before {
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;
}
h1 { font-size: 20px; margin: 0;}
h2 { font-size: 14px; }
pre {
font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace;
margin: 0;
padding: 0;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
a { color:#0074D9; text-decoration:none; }
a:hover { text-decoration:underline; }
.strong { font-weight: bold; }
.space-top1 { padding: 10px 0 0 0; }
.pad2y { padding: 20px 0; }
.pad1y { padding: 10px 0; }
.pad2x { padding: 0 20px; }
.pad2 { padding: 20px; }
.pad1 { padding: 10px; }
.space-left2 { padding-left:55px; }
.space-right2 { padding-right:20px; }
.center { text-align:center; }
.clearfix { display:block; }
.clearfix:after {
content:'';
display:block;
height:0;
clear:both;
visibility:hidden;
}
.fl { float: left; }
@media only screen and (max-width:640px) {
.col3 { width:100%; max-width:100%; }
.hide-mobile { display:none!important; }
}
.quiet {
color: #7f7f7f;
color: rgba(0,0,0,0.5);
}
.quiet a { opacity: 0.7; }
.fraction {
font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace;
font-size: 10px;
color: #555;
background: #E8E8E8;
padding: 4px 5px;
border-radius: 3px;
vertical-align: middle;
}
div.path a:link, div.path a:visited { color: #333; }
table.coverage {
border-collapse: collapse;
margin: 10px 0 0 0;
padding: 0;
}
table.coverage td {
margin: 0;
padding: 0;
vertical-align: top;
}
table.coverage td.line-count {
text-align: right;
padding: 0 5px 0 20px;
}
table.coverage td.line-coverage {
text-align: right;
padding-right: 10px;
min-width:20px;
}
table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 100%;
}
.missing-if-branch {
display: inline-block;
margin-right: 5px;
border-radius: 3px;
position: relative;
padding: 0 4px;
background: #333;
color: yellow;
}
.skip-if-branch {
display: none;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: #ccc;
color: white;
}
.missing-if-branch .typ, .skip-if-branch .typ {
color: inherit !important;
}
.coverage-summary {
border-collapse: collapse;
width: 100%;
}
.coverage-summary tr { border-bottom: 1px solid #bbb; }
.keyline-all { border: 1px solid #ddd; }
.coverage-summary td, .coverage-summary th { padding: 10px; }
.coverage-summary tbody { border: 1px solid #bbb; }
.coverage-summary td { border-right: 1px solid #bbb; }
.coverage-summary td:last-child { border-right: none; }
.coverage-summary th {
text-align: left;
font-weight: normal;
white-space: nowrap;
}
.coverage-summary th.file { border-right: none !important; }
.coverage-summary th.pct { }
.coverage-summary th.pic,
.coverage-summary th.abs,
.coverage-summary td.pct,
.coverage-summary td.abs { text-align: right; }
.coverage-summary td.file { white-space: nowrap; }
.coverage-summary td.pic { min-width: 120px !important; }
.coverage-summary tfoot td { }
.coverage-summary .sorter {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
}
.coverage-summary .sorted .sorter {
background-position: 0 -20px;
}
.coverage-summary .sorted-desc .sorter {
background-position: 0 -10px;
}
.status-line { height: 10px; }
/* dark red */
.red.solid, .status-line.low, .low .cover-fill { background:#C21F39 }
.low .chart { border:1px solid #C21F39 }
/* medium red */
.cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE }
/* light red */
.low, .cline-no { background:#FCE1E5 }
/* light green */
.high, .cline-yes { background:rgb(230,245,208) }
/* medium green */
.cstat-yes { background:rgb(161,215,106) }
/* dark green */
.status-line.high, .high .cover-fill { background:rgb(77,146,33) }
.high .chart { border:1px solid rgb(77,146,33) }
/* dark yellow (gold) */
.medium .chart { border:1px solid #f9cd0b; }
.status-line.medium, .medium .cover-fill { background: #f9cd0b; }
/* light yellow */
.medium { background: #fff4c2; }
/* light gray */
span.cline-neutral { background: #eaeaea; }
.cbranch-no { background: yellow !important; color: #111; }
.cstat-skip { background: #ddd; color: #111; }
.fstat-skip { background: #ddd; color: #111 !important; }
.cbranch-skip { background: #ddd !important; color: #111; }
.cover-fill, .cover-empty {
display:inline-block;
height: 12px;
}
.chart {
line-height: 0;
}
.cover-empty {
background: white;
}
.cover-full {
border-right: none !important;
}
pre.prettyprint {
border: none !important;
padding: 0 !important;
margin: 0 !important;
}
.com { color: #999 !important; }
.ignore-none { color: #999; font-weight: normal; }
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -48px;
}
.footer, .push {
height: 48px;
}

View File

@ -0,0 +1,93 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for All files</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="prettify.css" />
<link rel="stylesheet" href="base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
/
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>61/61</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>18/18</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>16/16</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>61/61</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<div class="pad1">
<table class="coverage-summary">
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="src/"><a href="src/index.html">src/</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="61" class="abs high">61/61</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="18" class="abs high">18/18</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="16" class="abs high">16/16</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="61" class="abs high">61/61</td>
</tr>
</tbody>
</table>
</div><div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Thu Nov 16 2017 14:49:51 GMT+0100 (STD)
</div>
</div>
<script src="prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="sorter.js"></script>
</body>
</html>

View File

@ -0,0 +1 @@
.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

View File

@ -0,0 +1,158 @@
var addSorting = (function () {
"use strict";
var cols,
currentSort = {
index: 0,
desc: false
};
// returns the summary table element
function getTable() { return document.querySelector('.coverage-summary'); }
// returns the thead element of the summary table
function getTableHeader() { return getTable().querySelector('thead tr'); }
// returns the tbody element of the summary table
function getTableBody() { return getTable().querySelector('tbody'); }
// returns the th element for nth column
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }
// loads all columns
function loadColumns() {
var colNodes = getTableHeader().querySelectorAll('th'),
colNode,
cols = [],
col,
i;
for (i = 0; i < colNodes.length; i += 1) {
colNode = colNodes[i];
col = {
key: colNode.getAttribute('data-col'),
sortable: !colNode.getAttribute('data-nosort'),
type: colNode.getAttribute('data-type') || 'string'
};
cols.push(col);
if (col.sortable) {
col.defaultDescSort = col.type === 'number';
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
}
}
return cols;
}
// attaches a data attribute to every tr element with an object
// of data values keyed by column name
function loadRowData(tableRow) {
var tableCols = tableRow.querySelectorAll('td'),
colNode,
col,
data = {},
i,
val;
for (i = 0; i < tableCols.length; i += 1) {
colNode = tableCols[i];
col = cols[i];
val = colNode.getAttribute('data-value');
if (col.type === 'number') {
val = Number(val);
}
data[col.key] = val;
}
return data;
}
// loads all row data
function loadData() {
var rows = getTableBody().querySelectorAll('tr'),
i;
for (i = 0; i < rows.length; i += 1) {
rows[i].data = loadRowData(rows[i]);
}
}
// sorts the table using the data for the ith column
function sortByIndex(index, desc) {
var key = cols[index].key,
sorter = function (a, b) {
a = a.data[key];
b = b.data[key];
return a < b ? -1 : a > b ? 1 : 0;
},
finalSorter = sorter,
tableBody = document.querySelector('.coverage-summary tbody'),
rowNodes = tableBody.querySelectorAll('tr'),
rows = [],
i;
if (desc) {
finalSorter = function (a, b) {
return -1 * sorter(a, b);
};
}
for (i = 0; i < rowNodes.length; i += 1) {
rows.push(rowNodes[i]);
tableBody.removeChild(rowNodes[i]);
}
rows.sort(finalSorter);
for (i = 0; i < rows.length; i += 1) {
tableBody.appendChild(rows[i]);
}
}
// removes sort indicators for current column being sorted
function removeSortIndicators() {
var col = getNthColumn(currentSort.index),
cls = col.className;
cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
col.className = cls;
}
// adds sort indicators for current column being sorted
function addSortIndicators() {
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
}
// adds event listeners for all sorter widgets
function enableUI() {
var i,
el,
ithSorter = function ithSorter(i) {
var col = cols[i];
return function () {
var desc = col.defaultDescSort;
if (currentSort.index === i) {
desc = !currentSort.desc;
}
sortByIndex(i, desc);
removeSortIndicators();
currentSort.index = i;
currentSort.desc = desc;
addSortIndicators();
};
};
for (i =0 ; i < cols.length; i += 1) {
if (cols[i].sortable) {
// add the click event handler on the th so users
// dont have to click on those tiny arrows
el = getNthColumn(i).querySelector('.sorter').parentElement;
if (el.addEventListener) {
el.addEventListener('click', ithSorter(i));
} else {
el.attachEvent('onclick', ithSorter(i));
}
}
}
}
// adds sorting functionality to the UI
return function () {
if (!getTable()) {
return;
}
cols = loadColumns();
loadData(cols);
addSortIndicators();
enableUI();
};
})();
window.addEventListener('load', addSorting);

View File

@ -0,0 +1,93 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for src/</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="../prettify.css" />
<link rel="stylesheet" href="../base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="../index.html">all files</a> src/
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>61/61</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>18/18</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>16/16</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>61/61</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<div class="pad1">
<table class="coverage-summary">
<thead>
<tr>
<th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
<th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
<th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
<th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
<th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
<th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
<th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
<th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
</tr>
</thead>
<tbody><tr>
<td class="file high" data-value="throttle.ts"><a href="throttle.ts.html">throttle.ts</a></td>
<td data-value="100" class="pic high"><div class="chart"><div class="cover-fill cover-full" style="width: 100%;"></div><div class="cover-empty" style="width:0%;"></div></div></td>
<td data-value="100" class="pct high">100%</td>
<td data-value="61" class="abs high">61/61</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="18" class="abs high">18/18</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="16" class="abs high">16/16</td>
<td data-value="100" class="pct high">100%</td>
<td data-value="61" class="abs high">61/61</td>
</tr>
</tbody>
</table>
</div><div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Thu Nov 16 2017 14:49:51 GMT+0100 (STD)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../sorter.js"></script>
</body>
</html>

View File

@ -0,0 +1,638 @@
<!doctype html>
<html lang="en">
<head>
<title>Code coverage report for src/throttle.ts</title>
<meta charset="utf-8" />
<link rel="stylesheet" href="../prettify.css" />
<link rel="stylesheet" href="../base.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type='text/css'>
.coverage-summary .sorter {
background-image: url(../sort-arrow-sprite.png);
}
</style>
</head>
<body>
<div class='wrapper'>
<div class='pad1'>
<h1>
<a href="../index.html">all files</a> / <a href="index.html">src/</a> throttle.ts
</h1>
<div class='clearfix'>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Statements</span>
<span class='fraction'>61/61</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Branches</span>
<span class='fraction'>18/18</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Functions</span>
<span class='fraction'>16/16</span>
</div>
<div class='fl pad1y space-right2'>
<span class="strong">100% </span>
<span class="quiet">Lines</span>
<span class='fraction'>61/61</span>
</div>
</div>
</div>
<div class='status-line high'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">71×</span>
<span class="cline-any cline-yes">71×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">19×</span>
<span class="cline-any cline-yes">19×</span>
<span class="cline-any cline-yes">19×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">19×</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18×</span>
<span class="cline-any cline-yes">18×</span>
<span class="cline-any cline-yes">18×</span>
<span class="cline-any cline-yes">81×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">81×</span>
<span class="cline-any cline-yes">78×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">56×</span>
<span class="cline-any cline-yes">56×</span>
<span class="cline-any cline-yes">56×</span>
<span class="cline-any cline-yes">56×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">22×</span>
<span class="cline-any cline-yes">22×</span>
<span class="cline-any cline-yes">22×</span>
<span class="cline-any cline-yes">22×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-yes">7×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">15×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3×</span>
<span class="cline-any cline-yes">3×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">75×</span>
<span class="cline-any cline-yes">8×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">67×</span>
<span class="cline-any cline-yes">67×</span>
<span class="cline-any cline-yes">5×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">67×</span>
<span class="cline-any cline-yes">11×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">56×</span>
<span class="cline-any cline-yes">26×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">86×</span>
<span class="cline-any cline-yes">85×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">81×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">18×</span>
<span class="cline-any cline-yes">60×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">8×</span>
<span class="cline-any cline-yes">8×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">2×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-yes">4×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">const DEFAULT_MAX = 5;
&nbsp;
export interface Result&lt;T&gt; {
amountDone: number;
amountStarted: number;
amountResolved: number;
amountRejected: number;
amountNextCheckFalsey: number;
rejectedIndexes: number[];
resolvedIndexes: number[];
nextCheckFalseyIndexes: number[];
taskResults: T[];
}
&nbsp;
export interface Options {
maxInProgress?: number;
failFast?: boolean;
progressCallback?: &lt;T&gt;(result: Result&lt;T&gt;) =&gt; void;
nextCheck?: nextTaskCheck;
}
&nbsp;
/**
* Default checker which validates if a next task should begin.
* This can be overwritten to write own checks for example checking the amount
* of used ram and waiting till the ram is low enough for a next task.
*
* It should always resolve with a boolean, either `true` to start a next task
* or `false` to stop executing a new task.
*
* If this method rejects, the error will propagate to the caller
* @param status
* @param tasks
* @returns {Promise}
*/
const defaultNextTaskCheck: nextTaskCheck = &lt;T&gt;(status: Result&lt;T&gt;, tasks: Tasks&lt;T&gt;): Promise&lt;boolean&gt; =&gt; {
return new Promise((resolve, reject) =&gt; {
resolve(status.amountStarted &lt; tasks.length);
});
};
&nbsp;
const DEFAULT_OPTIONS = {
maxInProgress: DEFAULT_MAX,
failFast: false,
nextCheck: defaultNextTaskCheck
};
&nbsp;
export type Task&lt;T&gt; = () =&gt; Promise&lt;T&gt;;
export type Tasks&lt;T&gt; = Array&lt;Task&lt;T&gt;&gt;;
export type nextTaskCheck = &lt;T&gt;(status: Result&lt;T&gt;, tasks: Tasks&lt;T&gt;) =&gt; Promise&lt;boolean&gt;;
&nbsp;
/**
* Raw throttle function, which can return extra meta data.
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export function raw&lt;T&gt;(tasks: Tasks&lt;T&gt;, options?: Options): Promise&lt;Result&lt;T&gt;&gt; {
return new Promise((resolve, reject) =&gt; {
const myOptions = Object.assign({}, DEFAULT_OPTIONS, options);
const result: Result&lt;T&gt; = {
amountDone: 0,
amountStarted: 0,
amountResolved: 0,
amountRejected: 0,
amountNextCheckFalsey: 0,
rejectedIndexes: [],
resolvedIndexes: [],
nextCheckFalseyIndexes: [],
taskResults: []
};
&nbsp;
if (tasks.length === 0) {
return resolve(result);
}
&nbsp;
let failedFast = false;
let currentTaskIndex = 0;
const executeTask = (index: number) =&gt; {
result.amountStarted++;
&nbsp;
if (typeof tasks[index] === 'function') {
tasks[index]().then(
taskResult =&gt; {
result.taskResults[index] = taskResult;
result.resolvedIndexes.push(index);
result.amountResolved++;
taskDone();
},
error =&gt; {
result.taskResults[index] = error;
result.rejectedIndexes.push(index);
result.amountRejected++;
if (myOptions.failFast === true) {
failedFast = true;
return reject(result);
}
taskDone();
}
);
} else {
failedFast = true;
return reject(
new Error('tasks[' + index + ']: ' + tasks[index] + ', is supposed to be of type function')
);
}
};
&nbsp;
const taskDone = () =&gt; {
//make sure no more tasks are spawned when we failedFast
if (failedFast === true) {
return;
}
&nbsp;
result.amountDone++;
if (typeof (myOptions as Options).progressCallback === 'function') {
(myOptions as any).progressCallback(result);
}
if (result.amountDone === tasks.length) {
return resolve(result);
}
if (currentTaskIndex &lt; tasks.length) {
nextTask(currentTaskIndex++);
}
};
&nbsp;
const nextTask = (index: number) =&gt; {
//check if we can execute the next task
myOptions.nextCheck(result, tasks).then(canExecuteNextTask =&gt; {
if (canExecuteNextTask === true) {
//execute it
executeTask(index);
} else {
result.amountNextCheckFalsey++;
result.nextCheckFalseyIndexes.push(index);
taskDone();
}
}, reject);
};
&nbsp;
//spawn the first X task
for (let i = 0; i &lt; Math.min(myOptions.maxInProgress, tasks.length); i++) {
nextTask(currentTaskIndex++);
}
});
}
&nbsp;
/**
* Executes the raw function, but only return the task array
* @param tasks
* @param options
* @returns {Promise}
*/
function executeRaw&lt;T&gt;(tasks: Tasks&lt;T&gt;, options: Options): Promise&lt;T[]&gt; {
return new Promise((resolve, reject) =&gt; {
raw(tasks, options).then(
(result: Result&lt;T&gt;) =&gt; {
resolve(result.taskResults);
},
(error: Error | Result&lt;T&gt;) =&gt; {
if (error instanceof Error) {
reject(error);
} else {
reject(error.taskResults[error.rejectedIndexes[0]]);
}
}
);
});
}
&nbsp;
/**
* Simply run all the promises after each other, so in synchronous manner
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export function sync&lt;T&gt;(tasks: Tasks&lt;T&gt;, options?: Options): Promise&lt;T[]&gt; {
const myOptions = Object.assign({}, { maxInProgress: 1, failFast: true }, options);
return executeRaw(tasks, myOptions);
}
&nbsp;
/**
* Exposes the same behaviour as Promise.All(), but throttled!
* @param tasks required array of tasks to be executed
* @param options Options object
* @returns {Promise}
*/
export function all&lt;T&gt;(tasks: Tasks&lt;T&gt;, options?: Options): Promise&lt;T[]&gt; {
const myOptions = Object.assign({}, { failFast: true }, options);
return executeRaw(tasks, myOptions);
}
&nbsp;
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Thu Nov 16 2017 14:49:51 GMT+0100 (STD)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
<script src="../sorter.js"></script>
</body>
</html>

View File

@ -0,0 +1,120 @@
TN:
SF:/mnt/d/Projecten/Promise-parallel-throttle/src/throttle.ts
FN:35,(anonymous_0)
FN:36,(anonymous_1)
FN:57,raw
FN:58,(anonymous_3)
FN:78,(anonymous_4)
FN:83,(anonymous_5)
FN:89,(anonymous_6)
FN:108,(anonymous_7)
FN:126,(anonymous_8)
FN:128,(anonymous_9)
FN:153,executeRaw
FN:154,(anonymous_11)
FN:156,(anonymous_12)
FN:159,(anonymous_13)
FN:176,sync
FN:187,all
FNF:16
FNH:16
FNDA:71,(anonymous_0)
FNDA:71,(anonymous_1)
FNDA:19,raw
FNDA:19,(anonymous_3)
FNDA:81,(anonymous_4)
FNDA:56,(anonymous_5)
FNDA:22,(anonymous_6)
FNDA:75,(anonymous_7)
FNDA:86,(anonymous_8)
FNDA:85,(anonymous_9)
FNDA:8,executeRaw
FNDA:8,(anonymous_11)
FNDA:4,(anonymous_12)
FNDA:4,(anonymous_13)
FNDA:4,sync
FNDA:4,all
DA:1,1
DA:35,1
DA:36,71
DA:37,71
DA:41,1
DA:57,1
DA:58,19
DA:59,19
DA:60,19
DA:72,19
DA:73,1
DA:76,18
DA:77,18
DA:78,18
DA:79,81
DA:81,81
DA:82,78
DA:84,56
DA:85,56
DA:86,56
DA:87,56
DA:90,22
DA:91,22
DA:92,22
DA:93,22
DA:94,7
DA:95,7
DA:97,15
DA:101,3
DA:102,3
DA:108,18
DA:110,75
DA:111,8
DA:114,67
DA:115,67
DA:116,5
DA:118,67
DA:119,11
DA:121,56
DA:122,26
DA:126,18
DA:128,86
DA:129,85
DA:131,81
DA:133,4
DA:134,4
DA:135,4
DA:141,18
DA:142,60
DA:154,8
DA:155,8
DA:157,4
DA:160,4
DA:161,2
DA:163,2
DA:176,1
DA:177,4
DA:178,4
DA:187,1
DA:188,4
DA:189,4
LF:61
LH:61
BRDA:72,1,0,1
BRDA:72,1,1,18
BRDA:81,2,0,78
BRDA:81,2,1,3
BRDA:93,3,0,7
BRDA:93,3,1,15
BRDA:110,4,0,8
BRDA:110,4,1,67
BRDA:115,5,0,5
BRDA:115,5,1,62
BRDA:118,6,0,11
BRDA:118,6,1,56
BRDA:121,7,0,26
BRDA:121,7,1,30
BRDA:129,8,0,81
BRDA:129,8,1,4
BRDA:160,9,0,2
BRDA:160,9,1,2
BRF:18
BRH:18
end_of_record

View File

@ -0,0 +1,106 @@
{
"_from": "promise-parallel-throttle",
"_id": "promise-parallel-throttle@3.1.0",
"_inBundle": false,
"_integrity": "sha512-18gafVK+kfabwYl/RolyU7cp62EXtv4RhzRrSqdnlyp48tR8BZUK7fKEeG4nfERJcpkSyD3P50aW/qbZOsUmtw==",
"_location": "/promise-parallel-throttle",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "promise-parallel-throttle",
"name": "promise-parallel-throttle",
"escapedName": "promise-parallel-throttle",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#DEV:/",
"#USER"
],
"_resolved": "https://registry.npmjs.org/promise-parallel-throttle/-/promise-parallel-throttle-3.1.0.tgz",
"_shasum": "0fd4179e944cf94430582e632efde13b8b7bb43d",
"_spec": "promise-parallel-throttle",
"_where": "C:\\Users\\dklein\\cse\\duolito-client\\Kha\\Tools\\khamake",
"author": {
"name": "Dirk-Jan Wassink",
"email": "dirk.jan.wassink@gmail.com",
"url": "http://dirkjanwassink.nl"
},
"bugs": {
"url": "https://github.com/DJWassink/Promise-parallel-throttle/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "Run promises in parallel, but throttled",
"devDependencies": {
"@types/jest": "^19.2.2",
"@types/node": "^6.0.46",
"husky": "^0.14.3",
"jest": "^19.0.2",
"lint-staged": "^4.2.3",
"prettier": "^1.7.2",
"ts-jest": "^19.0.14",
"tslint": "^5.1.0",
"tslint-config-prettier": "^1.5.0",
"tslint-eslint-rules": "^4.1.1",
"typescript": "^2.6.1"
},
"homepage": "https://github.com/DJWassink/Promise-parallel-throttle#readme",
"jest": {
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testResultsProcessor": "<rootDir>/node_modules/ts-jest/coverageprocessor.js",
"testRegex": "(/tests/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
]
},
"keywords": [
"promise",
"async",
"parallel",
"throttle",
"promise.all()",
"sync",
"synchronously"
],
"license": "MIT",
"lint-staged": {
"*.{ts,js}": [
"prettier --write",
"tslint -c ./tslint.json",
"git add"
]
},
"main": "build/throttle.js",
"name": "promise-parallel-throttle",
"prettier": {
"printWidth": 120,
"tabWidth": 4,
"singleQuote": true,
"jsxBracketSameLine": true,
"bracketSpacing": true
},
"repository": {
"type": "git",
"url": "git+https://github.com/DJWassink/Promise-parallel-throttle.git"
},
"scripts": {
"build": "yarn lint && rm -rf ./build && tsc && npm run declarations",
"declarations": "tsc --declaration",
"lint": "tslint -p ./tsconfig.json",
"lint:fix": "tslint -p ./tsconfig.json --fix",
"precommit": "lint-staged",
"prepublish": "npm run build",
"prettier": "prettier --write \"src/**/*.ts*\"",
"test": "yarn lint && jest --coverage --no-cache",
"test:watch": "jest --watch"
},
"types": "./build/throttle.d.ts",
"version": "3.1.0"
}

View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"outDir": "./build",
"sourceMap": true,
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"lib": ["es6"],
"strict": true
},
"files": [
"./src/throttle.ts"
]
}

View File

@ -0,0 +1,20 @@
{
"extends": ["tslint:recommended", "tslint-config-prettier"],
"rulesDirectory": "node_modules/tslint-eslint-rules/dist/rules",
"rules": {
"object-literal-sort-keys": false,
"ordered-imports": false,
"member-ordering": false,
"variable-name": [true, "allow-leading-underscore", "allow-pascal-case"],
"interface-name": false,
"triple-equals": true,
"comment-format": false,
"eofline": false,
"no-empty-interface": false,
"array-type": [true, "array-simple"],
"arrow-parens": false,
"only-arrow-functions": false,
"object-literal-shorthand": false,
"no-console": [true, "log"]
}
}

File diff suppressed because it is too large Load Diff