25 Commits

Author SHA1 Message Date
eeb05aa987 3.0.4 2023-07-13 09:49:38 +02:00
1cc575d2c8 fix(core): update 2023-07-13 09:49:37 +02:00
3bcddff4ab 3.0.3 2023-07-13 09:44:41 +02:00
b7da538595 fix(core): update 2023-07-13 09:44:40 +02:00
aee7e17035 3.0.2 2023-07-10 23:13:12 +02:00
ddd6e45662 fix(core): update 2023-07-10 23:13:11 +02:00
3a9a8686a1 switch to new org scheme 2023-07-10 02:48:34 +02:00
499ae24297 3.0.1 2023-04-05 16:31:35 +02:00
820c6ccb74 fix(core): update 2023-04-05 16:31:34 +02:00
9b8198d592 3.0.0 2023-04-05 16:29:29 +02:00
1f0e574854 BREAKING CHANGE(core): update 2023-04-05 16:29:29 +02:00
9f305070eb 2.0.13 2021-06-04 15:35:42 +02:00
062f99990b fix(core): update 2021-06-04 15:35:41 +02:00
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
e49be654eb 2.0.10 2020-07-11 21:33:35 +00:00
9f599e79a1 fix(core): update 2020-07-11 21:33:34 +00:00
3821799070 2.0.9 2020-05-27 16:54:33 +00:00
80de670cad fix(core): update 2020-05-27 16:54:32 +00:00
2d64c43b55 2.0.8 2020-05-27 16:06:21 +00:00
0da614f1c0 fix(core): update 2020-05-27 16:06:21 +00:00
7daefcac11 2.0.7 2020-05-27 16:06:07 +00:00
912bdc61fb fix(core): update 2020-05-27 16:06:07 +00:00
15 changed files with 4922 additions and 1774 deletions

4
.gitignore vendored
View File

@@ -15,8 +15,6 @@ node_modules/
# builds # builds
dist/ dist/
dist_web/ dist_*/
dist_serve/
dist_ts_web/
# custom # custom

View File

@@ -12,29 +12,38 @@ stages:
- release - release
- metadata - metadata
before_script:
- pnpm install -g pnpm
- pnpm install -g @shipzone/npmci
- npmci npm prepare
# ==================== # ====================
# security stage # security stage
# ==================== # ====================
mirror: # ====================
# security stage
# ====================
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci git mirror - npmci command npm config set registry https://registry.npmjs.org
- npmci command pnpm audit --audit-level=high --prod
tags: tags:
- lossless - lossless
- docker - docker
- notpriv allow_failure: true
snyk: auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm install -g snyk - npmci command pnpm audit --audit-level=high --dev
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags: tags:
- lossless - lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@@ -43,28 +52,22 @@ snyk:
testStable: testStable:
stage: test stage: test
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- 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
script: script:
- npmci npm prepare
- npmci node install stable - npmci node install stable
- npmci npm install - npmci npm install
- npmci command npm run build - npmci npm build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@@ -84,11 +87,12 @@ 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 typescript
- npmci npm prepare - npmci npm prepare
- npmci npm install - npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags: tags:
- lossless - lossless
- docker - docker
@@ -108,11 +112,9 @@ trigger:
pages: pages:
stage: metadata stage: metadata
script: script:
- npmci node install lts - npmci node install stable
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install - npmci npm install
- npmci command tsdoc - npmci command npm run buildDocs
tags: tags:
- lossless - lossless
- docker - docker

11
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

View File

@@ -1,45 +0,0 @@
# @pushrocks/smartdelay
timeouts for the async/await era, written in TypeScript
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartdelay)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartdelay)
* [github.com (source mirror)](https://github.com/pushrocks/smartdelay)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdelay/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartdelay/badges/master/build.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)
[![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)
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage
Use TypeScript for best in class instellisense.
```javascript
import * as smartdelay from 'smartdelay';
(async () => {
await smartdelay.delayFor(3000); // excution will halt here 3 seconds for this function scope BUT NOT BLOCK anything else
console.log('hi there');
// You can also go random
await smartdelay.delayForRandom(2000, 6000); // this will delay exection somewhere between 2 and 6 seconds.
console.log('Yay. You did not see me coming at this exact time');
})();
```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@@ -4,12 +4,13 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartdelay", "gitrepo": "smartdelay",
"shortDescription": "timeouts for the async/await era, written in TypeScript", "description": "timeouts for the async/await era, written in TypeScript",
"npmPackagename": "@pushrocks/smartdelay", "npmPackagename": "@push.rocks/smartdelay",
"license": "MIT" "license": "MIT"
} }
} }

1634
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,14 @@
{ {
"name": "@pushrocks/smartdelay", "name": "@push.rocks/smartdelay",
"private": false, "private": false,
"version": "2.0.6", "version": "3.0.4",
"description": "timeouts for the async/await era, written in TypeScript", "description": "timeouts for the async/await era, written in TypeScript",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)" "build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
"buildDocs": "tsdoc"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -20,26 +21,30 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartdelay#README", "homepage": "https://gitlab.com/pushrocks/smartdelay#README",
"dependencies": { "dependencies": {
"@pushrocks/smartpromise": "^3.0.6" "@push.rocks/smartpromise": "^4.0.2"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.66",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsbundle": "^2.0.8",
"@gitzone/tstest": "^1.0.28", "@gitzone/tsrun": "^1.2.42",
"@pushrocks/tapbundle": "^3.0.13", "@gitzone/tstest": "^1.0.74",
"@types/node": "^12.12.5", "@push.rocks/tapbundle": "^5.0.8",
"tslint": "^5.20.0", "@types/node": "^20.4.1"
"tslint-config-prettier": "^1.18.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",
"ts_web/**/*", "ts_web/**/*",
"dist/**/*", "dist/**/*",
"dist_web/**/*", "dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*", "dist_ts_web/**/*",
"assets/**/*", "assets/**/*",
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ],
"browserslist": [
"last 1 chrome versions"
],
"type": "module"
} }

4711
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

50
readme.md Normal file
View File

@@ -0,0 +1,50 @@
# @push.rocks/smartdelay
timeouts for the async/await era, written in TypeScript
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartdelay)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartdelay)
* [github.com (source mirror)](https://github.com/pushrocks/smartdelay)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartdelay/)
## Status for master
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartdelay/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartdelay/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartdelay)](https://lossless.cloud)
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/@push.rocks/smartdelay)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartdelay)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartdelay)](https://lossless.cloud)
## Usage
Use TypeScript for best in class instellisense.
```javascript
import * as smartdelay from 'smartdelay';
(async () => {
await smartdelay.delayFor(3000); // excution will halt here 3 seconds for this function scope BUT NOT BLOCK anything else
console.log('hi there');
// You can also go random
await smartdelay.delayForRandom(2000, 6000); // this will delay exection somewhere between 2 and 6 seconds.
console.log('Yay. You did not see me coming at this exact time');
})();
```
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
For further information read the linked docs at the top of this readme.
## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)

View File

@@ -1,8 +1,8 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as smartdelay from '../ts/index'; import * as smartdelay from '../ts/index.js';
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(() => {
@@ -10,11 +10,11 @@ tap.test('.delayFor should delay async', async tools => {
}, 2000); }, 2000);
await smartdelay.delayFor(3000).then(async () => { await smartdelay.delayFor(3000).then(async () => {
// tslint:disable-next-line:no-unused-expression // tslint:disable-next-line:no-unused-expression
expect(timePassed).to.be.true; expect(timePassed).toBeTrue();
}); });
}); });
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(() => {
@@ -24,19 +24,19 @@ tap.test('.delayForRandom should delay async for a random time period', async to
timePassedAfter = true; timePassedAfter = true;
}, 5000); }, 5000);
await smartdelay.delayForRandom(3000, 4900); await smartdelay.delayForRandom(3000, 4900);
expect(timePassedBefore).to.be.true; expect(timePassedBefore).toBeTrue();
expect(timePassedAfter).to.be.false; expect(timePassedAfter).toBeFalse();
}); });
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).toEqual('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();
}); });

8
ts/00_commitinfo_data.ts Normal file
View File

@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartdelay',
version: '3.0.4',
description: 'timeouts for the async/await era, written in TypeScript'
}

View File

@@ -1,41 +1,48 @@
import * as smartpromise from '@pushrocks/smartpromise'; import * as smartpromise from '@push.rocks/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> {
promise: Promise<T>; promise: Promise<T>;
private _deferred: smartpromise.Deferred<T>; private _deferred: smartpromise.Deferred<T>;
private _timeout: any; private _timeout;
private _cancelled: boolean = false; private _cancelled: boolean = false;
constructor(timeInMillisecondArg, passOn?: T) {
private timeoutInMillis: number;
private started: number;
constructor(timeInMillisecondArg, passOn?: T, unrefedArg = false) {
this.timeoutInMillis = timeInMillisecondArg;
this._deferred = smartpromise.defer<T>(); this._deferred = smartpromise.defer<T>();
this.promise = this._deferred.promise; this.promise = this._deferred.promise;
this._timeout = setTimeout(() => { this._timeout = setTimeout(() => {
@@ -43,14 +50,29 @@ export class Timeout<T> {
this._deferred.resolve(passOn); this._deferred.resolve(passOn);
} }
}, timeInMillisecondArg); }, timeInMillisecondArg);
} this.started = Date.now();
if (unrefedArg) {
makeUnrefed() {
this._timeout.unref();
}
cancel() {
this._cancelled = true;
this.makeUnrefed(); this.makeUnrefed();
} }
} }
/**
* unreffing a timeout causes the node process to not wait for completion before exit
*/
public makeUnrefed() {
this._timeout.unref();
}
/**
* cancels the timer
*/
public cancel() {
this._cancelled = true;
clearTimeout(this._timeout);
}
public getTimeLeft() {
const result = this.started + this.timeoutInMillis - Date.now();
return result > 0 ? result : 0;
}
}

10
tsconfig.json Normal file
View File

@@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true
}
}

View File

@@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}