15 Commits

Author SHA1 Message Date
a99767986d 2.0.3 2019-03-26 12:43:01 +01:00
647a9ab4cb fix(core): update 2019-03-26 12:43:01 +01:00
ffb4d1c29e 2.0.2 2018-08-08 23:25:48 +02:00
f4480aa289 fix(CI): switch to new build stack 2018-08-08 23:25:48 +02:00
f952c71e2d 2.0.1 2018-07-06 14:26:01 +02:00
4edbd04c77 fix(access): fix accesslevels for npm 2018-07-06 14:26:00 +02:00
9acff87870 2.0.0 2018-07-06 14:20:56 +02:00
767b3d6e42 BREAKING CHANGE(switch scope): update 2018-07-06 14:20:56 +02:00
deb8f2004d 1.0.4 2017-10-09 11:42:22 +02:00
62a5975fb3 implement random time 2017-10-09 11:33:59 +02:00
645a1ca111 update ci 2017-10-09 11:26:37 +02:00
e67b148c41 1.0.3 2017-06-05 00:34:03 +02:00
f462bb1641 update ci 2017-06-05 00:33:59 +02:00
553bfa2735 1.0.2 2017-06-05 00:32:05 +02:00
75358d0b66 add cancelable Timeout 2017-06-05 00:32:01 +02:00
11 changed files with 1891 additions and 121 deletions

View File

@@ -1,59 +1,141 @@
image: hosttoday/ht-docker-node:npmts # gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages: stages:
- security
- test - test
- release - release
- trigger - metadata
- pages
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
# ====================
# test stage
# ====================
testLEGACY: testLEGACY:
stage: test stage: test
script: script:
- npmci test legacy - npmci node install legacy
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
allow_failure: true allow_failure: true
testLTS: testLTS:
stage: test stage: test
script: script:
- npmci test lts - npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
testSTABLE: testSTABLE:
stage: test stage: test
script: script:
- npmci test stable - npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- docker - docker
- notpriv
release: release:
stage: release stage: release
script: script:
- npmci publish - npmci node install stable
- npmci npm publish
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- docker
- priv
trigger: trigger:
stage: trigger stage: metadata
script: script:
- npmci trigger - npmci trigger
only: only:
- tags - tags
tags: tags:
- docker - docker
- notpriv
pages: pages:
image: hosttoday/ht-docker-node:npmpage image: hosttoday/ht-docker-node:npmci
stage: pages stage: metadata
script: script:
- npmci command npmpage --publish gitlab - npmci command npm install -g npmpage
- npmci command npmpage
tags:
- docker
- notpriv
only: only:
- tags - tags
artifacts: artifacts:
expire_in: 1 week expire_in: 1 week
paths: paths:
- public - public
allow_failure: true
windowsCompatibility:
image: stefanscherer/node-windows:10-build-tools
stage: metadata
script:
- npm install & npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- windows
allow_failure: true

View File

@@ -1,13 +1,16 @@
# smartdelay # @pushrocks/smartdelay
timeouts for the async/await era, written in TypeScript timeouts for the async/await era, written in TypeScript
## Availabililty ## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartdelay) [![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartdelay)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdelay) [![git](https://push.rocks/assets/repo-button-git.svg)](https://GitLab.com/pushrocks/smartdelay)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdelay) [![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartdelay)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdelay/) [![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartdelay/)
## Status for master ## Status for master
[![build status](https://GitLab.com/pushrocks/smartdelay/badges/master/build.svg)](https://GitLab.com/pushrocks/smartdelay/commits/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) [![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/smartdelay.svg)](https://www.npmjs.com/package/smartdelay) [![npm downloads per month](https://img.shields.io/npm/dm/smartdelay.svg)](https://www.npmjs.com/package/smartdelay)
@@ -19,15 +22,16 @@ timeouts for the async/await era, written in TypeScript
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) [![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage ## Usage
Use TypeScript for best in class instellisense. Use TypeScript for best in class instellisense.
```javascript ```javascript
import * as smartdelay from 'smartdelay' import * as smartdelay from 'smartdelay';
(async () => { (async () => {
await smartdelay.delayFor('3000') // excution will halt here 3 seconds for this function scope BUT NOT BLOCK anything else await smartdelay.delayFor('3000'); // excution will halt here 3 seconds for this function scope BUT NOT BLOCK anything else
console.log() console.log();
})() })();
``` ```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks) [![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

2
dist/index.d.ts vendored
View File

@@ -1,2 +0,0 @@
import 'typings-global';
export declare let delayFor: <T>(timeInMillisecond: number, passOn?: T) => Promise<T>;

19
dist/index.js vendored
View File

@@ -1,19 +0,0 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
require("typings-global");
exports.delayFor = (timeInMillisecond, passOn) => __awaiter(this, void 0, void 0, function* () {
yield new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, timeInMillisecond);
});
return passOn;
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSwwQkFBdUI7QUFFWixRQUFBLFFBQVEsR0FBRyxDQUFVLGlCQUF5QixFQUFFLE1BQVU7SUFDakUsTUFBTSxJQUFJLE9BQU8sQ0FBQyxDQUFDLE9BQU8sRUFBRSxNQUFNO1FBQzlCLFVBQVUsQ0FDTjtZQUNJLE9BQU8sRUFBRSxDQUFBO1FBQ2IsQ0FBQyxFQUNELGlCQUFpQixDQUNwQixDQUFBO0lBQ0wsQ0FBQyxDQUFDLENBQUE7SUFDRixNQUFNLENBQUMsTUFBTSxDQUFBO0FBQ2pCLENBQUMsQ0FBQSxDQUFBIn0=

6
npmextra.json Normal file
View File

@@ -0,0 +1,6 @@
{
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}

1663
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,13 @@
{ {
"name": "smartdelay", "name": "@pushrocks/smartdelay",
"version": "1.0.1", "private": false,
"version": "2.0.3",
"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/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",
"scripts": { "scripts": {
"test": "(npmts)" "test": "(tstest test/)",
"build": "(tsbuild)"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -18,11 +20,13 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartdelay#README", "homepage": "https://gitlab.com/pushrocks/smartdelay#README",
"dependencies": { "dependencies": {
"typings-global": "^1.0.14" "@pushrocks/smartpromise": "^3.0.2"
}, },
"devDependencies": { "devDependencies": {
"@types/should": "^8.1.30", "@gitzone/tsbuild": "^2.1.8",
"should": "^11.1.2", "@gitzone/tsrun": "^1.2.1",
"typings-test": "^1.0.3" "@gitzone/tstest": "^1.0.18",
"@types/node": "^11.11.7",
"tapbundle": "^2.0.2"
} }
} }

1
test/test.d.ts vendored
View File

@@ -1 +0,0 @@
import 'typings-test';

View File

@@ -1,30 +0,0 @@
"use strict";
require("typings-test");
const should = require("should");
const smartdelay = require("../dist/index");
describe('smartdelay', function () {
it('.delayFor should delay async', function (done) {
this.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
smartdelay.delayFor(3000).then(() => {
should(timePassed).be.true();
done();
});
});
it('.delayFor should pass on a type', function (done) {
this.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
let hey = 'heyThere';
smartdelay.delayFor(3000, hey).then((stringArg) => {
should(stringArg).equal('heyThere');
done();
});
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZX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FFLENBQUE7UUFDVixDQUFDLENBQUMsQ0FBQTtJQUNOLENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==

View File

@@ -1,31 +1,51 @@
import 'typings-test' import { expect, tap } from 'tapbundle';
import * as should from 'should' import * as smartdelay from '../ts/index';
import * as smartdelay from '../dist/index' tap.test('.delayFor should delay async', async tools => {
tools.timeout(5000);
describe('smartdelay', function () { let timePassed = false;
it('.delayFor should delay async', function(done) {
this.timeout(5000)
let timePassed = false
setTimeout(() => { setTimeout(() => {
timePassed = true timePassed = true;
},2000) }, 2000);
smartdelay.delayFor(3000).then(() => { await smartdelay.delayFor(3000).then(async () => {
should(timePassed).be.true() // tslint:disable-next-line:no-unused-expression
done() expect(timePassed).to.be.true;
}) });
}) });
it('.delayFor should pass on a type', function(done) {
this.timeout(5000) tap.test('.delayForRandpm should delay async for a random time period', async tools => {
let timePassed = false tools.timeout(5000);
let timePassed = false;
setTimeout(() => { setTimeout(() => {
timePassed = true timePassed = true;
},2000) }, 3000);
let hey = 'heyThere' await smartdelay.delayForRandom(3000, 4900).then(async () => {
smartdelay.delayFor<string>(3000, hey).then((stringArg) => { // tslint:disable-next-line:no-unused-expression
should(stringArg).equal('heyThere') expect(timePassed).to.be.true;
done() });
}) });
})
}) tap.test('.delayFor should pass on a type', async tools => {
tools.timeout(5000);
let timePassed = false;
setTimeout(() => {
timePassed = true;
}, 2000);
let hey = 'heyThere';
await smartdelay.delayFor<string>(3000, hey).then(async stringArg => {
expect(stringArg).equal('heyThere');
});
});
tap.test('smartdelay.Timeout', async () => {
let timeout = new smartdelay.Timeout(2000);
await timeout.promise;
});
tap.test('smartdelay.Timeout should cancel', async tools => {
let timeout = new smartdelay.Timeout(60000);
timeout.cancel();
});
tap.start();

View File

@@ -1,13 +1,56 @@
import 'typings-global' import * as smartpromise from '@pushrocks/smartpromise';
/**
* delay something, works like setTimeout
* @param timeInMillisecond
* @param passOn
*/
export let delayFor = async <T>(timeInMillisecond: number, passOn?: T) => { export let delayFor = async <T>(timeInMillisecond: number, passOn?: T) => {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
setTimeout( setTimeout(() => {
() => { resolve();
resolve() }, timeInMillisecond);
}, });
timeInMillisecond return passOn;
) };
})
return passOn /**
* delay for a random time
*/
export let delayForRandom = async <T>(
timeMinInMillisecond: number,
timeMaxInMillisecond: number,
passOn?: T
) => {
await new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, Math.random() * (timeMaxInMillisecond - timeMinInMillisecond) + timeMinInMillisecond);
});
return passOn;
};
export class Timeout<T> {
promise: Promise<T>;
private _deferred: smartpromise.Deferred<T>;
private _timeout: any;
private _cancelled: boolean = false;
constructor(timeInMillisecondArg, passOn?: T) {
this._deferred = smartpromise.defer<T>();
this.promise = this._deferred.promise;
this._timeout = setTimeout(() => {
if (!this._cancelled) {
this._deferred.resolve(passOn);
}
}, timeInMillisecondArg);
}
makeUnrefed() {
this._timeout.unref();
}
cancel() {
this._cancelled = true;
this.makeUnrefed();
}
} }