fix(core): update
This commit is contained in:
parent
0526c45ea1
commit
ee336af699
25
.gitignore
vendored
25
.gitignore
vendored
@ -1,5 +1,22 @@
|
||||
coverage/
|
||||
pages/
|
||||
node_modules/
|
||||
public/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
@ -1,5 +1,5 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@ -38,19 +38,7 @@ snyk:
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
@ -60,6 +48,18 @@ testSTABLE:
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
@ -78,19 +78,11 @@ release:
|
||||
# ====================
|
||||
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]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@ -106,13 +98,15 @@ trigger:
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
image: hosttoday/ht-docker-dbase:npmci
|
||||
services:
|
||||
- docker:stable-dind
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g typedoc typescript
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
26
README.md
26
README.md
@ -1,13 +1,16 @@
|
||||
# @pushrocks/smartpromise
|
||||
|
||||
simple promises and Deferred constructs
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpromise)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartpromise)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartpromise)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartpromise/)
|
||||
|
||||
- [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartpromise)
|
||||
- [gitlab.com (source)](https://gitlab.com/pushrocks/smartpromise)
|
||||
- [github.com (source mirror)](https://github.com/pushrocks/smartpromise)
|
||||
- [docs (typedoc)](https://pushrocks.gitlab.io/smartpromise/)
|
||||
|
||||
## Status for master
|
||||
|
||||
[![build status](https://gitlab.com/pushrocks/smartpromise/badges/master/build.svg)](https://gitlab.com/pushrocks/smartpromise/commits/master)
|
||||
[![coverage report](https://gitlab.com/pushrocks/smartpromise/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartpromise/commits/master)
|
||||
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartpromise.svg)](https://www.npmjs.com/package/@pushrocks/smartpromise)
|
||||
@ -23,7 +26,7 @@ Use TypeScript for best in class instellisense.
|
||||
> Note: smartq uses native ES6 promises
|
||||
> smartq does not repeat any native functions, so for things like .all() simply use Promise.all()
|
||||
|
||||
```javascript
|
||||
```typescript
|
||||
import * as q from '@pushrocks/smartpromise'
|
||||
|
||||
// Deferred
|
||||
@ -32,7 +35,14 @@ let myAsyncFunction = (): Promise<string> => {
|
||||
let done = q.defer<string>() // returns your typical Deferred object
|
||||
setTimeout(() => {
|
||||
done.resolve('hi') // will throw type error for other types than string as argument ;)
|
||||
},6000)
|
||||
},6000);
|
||||
|
||||
console.log(done.status) // logs "pending";
|
||||
done.promise.then(() => {
|
||||
console.log(done.status) // logs "fullfilled"
|
||||
console.log(done.duration) // logs the milliseconds between instantiation and fullfillment
|
||||
})
|
||||
|
||||
return done.promise
|
||||
}
|
||||
|
||||
@ -75,6 +85,6 @@ myPromisedFunction('helloThere', 2).then(x => {
|
||||
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.html)
|
||||
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com)
|
||||
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
|
||||
|
@ -1,8 +1,6 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"npmts"
|
||||
],
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
|
1476
package-lock.json
generated
1476
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@ -6,8 +6,8 @@
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tsrun test/test.ts)",
|
||||
"build": "(npmts)"
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -21,8 +21,22 @@
|
||||
"homepage": "https://gitlab.com/pushrocks/smartq#README",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsrun": "^1.0.18",
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tstest": "^1.0.24",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^10.5.1",
|
||||
"tapbundle": "^2.0.0"
|
||||
}
|
||||
"tslint": "^5.20.0",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"dist_ts_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { expect, tap } from 'tapbundle';
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as q from '../ts/index';
|
||||
|
||||
tap.test('should return a Deferred for .defer()', async () => {
|
||||
|
32
ts/index.ts
32
ts/index.ts
@ -9,14 +9,34 @@ export interface IReject {
|
||||
export type TDeferredStatus = 'pending' | 'fulfilled' | 'rejected';
|
||||
|
||||
export class Deferred<T> {
|
||||
promise: Promise<T>;
|
||||
resolve: IResolve<T>;
|
||||
reject: IReject;
|
||||
status: TDeferredStatus;
|
||||
public promise: Promise<T>;
|
||||
public resolve: IResolve<T>;
|
||||
public reject: IReject;
|
||||
public status: TDeferredStatus;
|
||||
|
||||
public startedAt: number;
|
||||
public stoppedAt: number;
|
||||
public get duration(): number {
|
||||
if (this.stoppedAt) {
|
||||
return this.stoppedAt - this.startedAt;
|
||||
} else {
|
||||
return Date.now() - this.startedAt;
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.promise = new Promise<T>((resolve, reject) => {
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
this.resolve = (valueArg: T | PromiseLike<T>) => {
|
||||
this.status = 'fulfilled';
|
||||
this.stoppedAt = Date.now();
|
||||
resolve(valueArg);
|
||||
};
|
||||
this.reject = (reason: any) => {
|
||||
this.status = 'rejected';
|
||||
this.stoppedAt = Date.now();
|
||||
reject(reason);
|
||||
};
|
||||
this.startedAt = Date.now();
|
||||
this.status = 'pending';
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user