4 Commits

Author SHA1 Message Date
d3201b0d35 2.0.12 2021-06-04 14:11:27 +02:00
5df94778dd fix(core): update 2021-06-04 14:11:27 +02:00
2dc91dc2f0 2.0.11 2021-06-04 13:54:21 +02:00
3784de03ce fix(core): update 2021-06-04 13:54:21 +02:00
7 changed files with 23346 additions and 1291 deletions

View File

@@ -19,23 +19,36 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
audit: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high - npmci command npm audit --audit-level=high --only=dev
tags: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@@ -50,9 +63,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@@ -63,9 +74,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@@ -85,6 +94,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

View File

@@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

24575
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
{ {
"name": "@pushrocks/smartdelay", "name": "@pushrocks/smartdelay",
"private": false, "private": false,
"version": "2.0.10", "version": "2.0.12",
"description": "timeouts for the async/await era, written in TypeScript", "description": "timeouts for the async/await era, written in TypeScript",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts", "typings": "dist_ts/index.d.ts",
@@ -28,7 +28,7 @@
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.2.1", "@pushrocks/tapbundle": "^3.2.1",
"@types/node": "^14.0.5", "@types/node": "^15.12.0",
"tslint": "^6.1.2", "tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0" "tslint-config-prettier": "^1.18.0"
}, },
@@ -43,5 +43,8 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
],
"browserslist": [
"last 1 chrome versions"
] ]
} }

View File

@@ -8,13 +8,20 @@ timeouts for the async/await era, written in TypeScript
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdelay/) * [docs (typedoc)](https://pushrocks.gitlab.io/smartdelay/)
## Status for master ## Status for master
[![pipeline status](https://gitlab.com/pushrocks/smartdelay/badges/master/pipeline.svg)](https://gitlab.com/pushrocks/smartdelay/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartdelay/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartdelay/commits/master) Status Category | Status Badge
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartdelay.svg)](https://www.npmjs.com/package/@pushrocks/smartdelay) -- | --
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartdelay/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartdelay) GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartdelay/badges/master/pipeline.svg)](https://lossless.cloud)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartdelay/badges/master/coverage.svg)](https://lossless.cloud)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartdelay)](https://lossless.cloud)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartdelay)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartdelay)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartdelay)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartdelay)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage

View File

@@ -2,7 +2,7 @@ import { expect, tap } from '@pushrocks/tapbundle';
import * as smartdelay from '../ts/index'; import * as smartdelay from '../ts/index';
tap.test('.delayFor should delay async', async tools => { tap.test('.delayFor should delay async', async (tools) => {
tools.timeout(5000); tools.timeout(5000);
let timePassed = false; let timePassed = false;
setTimeout(() => { setTimeout(() => {
@@ -14,7 +14,7 @@ tap.test('.delayFor should delay async', async tools => {
}); });
}); });
tap.test('.delayForRandom should delay async for a random time period', async tools => { tap.test('.delayForRandom should delay async for a random time period', async (tools) => {
let timePassedBefore = false; let timePassedBefore = false;
let timePassedAfter = false; let timePassedAfter = false;
setTimeout(() => { setTimeout(() => {
@@ -28,14 +28,14 @@ tap.test('.delayForRandom should delay async for a random time period', async to
expect(timePassedAfter).to.be.false; expect(timePassedAfter).to.be.false;
}); });
tap.test('.delayFor should pass on a type', async tools => { tap.test('.delayFor should pass on a type', async (tools) => {
tools.timeout(5000); tools.timeout(5000);
let timePassed = false; let timePassed = false;
setTimeout(() => { setTimeout(() => {
timePassed = true; timePassed = true;
}, 2000); }, 2000);
let hey = 'heyThere'; let hey = 'heyThere';
await smartdelay.delayFor<string>(3000, hey).then(async stringArg => { await smartdelay.delayFor<string>(3000, hey).then(async (stringArg) => {
expect(stringArg).equal('heyThere'); expect(stringArg).equal('heyThere');
}); });
}); });
@@ -45,7 +45,7 @@ tap.test('smartdelay.Timeout', async () => {
await timeout.promise; await timeout.promise;
}); });
tap.test('smartdelay.Timeout should cancel', async tools => { tap.test('smartdelay.Timeout should cancel', async (tools) => {
let timeout = new smartdelay.Timeout(60000); let timeout = new smartdelay.Timeout(60000);
timeout.cancel(); timeout.cancel();
}); });

View File

@@ -2,32 +2,34 @@ import * as smartpromise from '@pushrocks/smartpromise';
/** /**
* delay something, works like setTimeout * delay something, works like setTimeout
* @param timeInMillisecond * @param timeInMillisecondArg
* @param passOn * @param passOnArg
*/ */
export let delayFor = async <T>(timeInMillisecond: number, passOn?: T) => { export let delayFor = async <T>(
await new Promise((resolve, reject) => { timeInMillisecondArg: number,
setTimeout(() => { passOnArg?: T,
resolve(); unrefedArg = false
}, timeInMillisecond); ) => {
}); const timeout = new Timeout(timeInMillisecondArg, null, unrefedArg);
return passOn; await timeout.promise;
return passOnArg;
}; };
/** /**
* delay for a random time * delay for a random time
*/ */
export let delayForRandom = async <T>( export let delayForRandom = async <T>(
timeMinInMillisecond: number, timeMinInMillisecondArg: number,
timeMaxInMillisecond: number, timeMaxInMillisecondArg: number,
passOn?: T passOnArg?: T,
unrefedArg = false
) => { ) => {
await new Promise((resolve, reject) => { await delayFor(
setTimeout(() => { Math.random() * (timeMaxInMillisecondArg - timeMinInMillisecondArg) + timeMinInMillisecondArg,
resolve(); null,
}, Math.random() * (timeMaxInMillisecond - timeMinInMillisecond) + timeMinInMillisecond); unrefedArg
}); );
return passOn; return passOnArg;
}; };
export class Timeout<T> { export class Timeout<T> {
@@ -39,7 +41,7 @@ export class Timeout<T> {
private timeoutInMillis: number; private timeoutInMillis: number;
private started: number; private started: number;
constructor(timeInMillisecondArg, passOn?: T) { constructor(timeInMillisecondArg, passOn?: T, unrefedArg = false) {
this.timeoutInMillis = timeInMillisecondArg; this.timeoutInMillis = timeInMillisecondArg;
this._deferred = smartpromise.defer<T>(); this._deferred = smartpromise.defer<T>();
this.promise = this._deferred.promise; this.promise = this._deferred.promise;
@@ -49,6 +51,9 @@ export class Timeout<T> {
} }
}, timeInMillisecondArg); }, timeInMillisecondArg);
this.started = Date.now(); this.started = Date.now();
if (unrefedArg) {
this.makeUnrefed();
}
} }
/** /**