Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pushrocks/smartpromise

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pushrocks/smartpromise - npm Package Compare versions

Comparing version 3.0.2 to 3.0.5

5

dist/index.d.ts
export interface IResolve<T> {
(value?: T | Promise<T>): void;
(value?: T | PromiseLike<T>): void;
}

@@ -13,2 +13,5 @@ export interface IReject {

status: TDeferredStatus;
startedAt: number;
stoppedAt: number;
readonly duration: number;
constructor();

@@ -15,0 +18,0 @@ }

37

dist/index.js
"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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -14,7 +6,24 @@ class Deferred {

this.promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
this.resolve = (valueArg) => {
this.status = 'fulfilled';
this.stoppedAt = Date.now();
resolve(valueArg);
};
this.reject = (reason) => {
this.status = 'rejected';
this.stoppedAt = Date.now();
reject(reason);
};
this.startedAt = Date.now();
this.status = 'pending';
});
}
get duration() {
if (this.stoppedAt) {
return this.stoppedAt - this.startedAt;
}
else {
return Date.now() - this.startedAt;
}
}
}

@@ -37,3 +46,3 @@ exports.Deferred = Deferred;

};
exports.map = (inputArg, functionArg) => __awaiter(this, void 0, void 0, function* () {
exports.map = async (inputArg, functionArg) => {
let promiseArray = [];

@@ -48,5 +57,5 @@ let resultArray = [];

}
yield Promise.all(promiseArray);
await Promise.all(promiseArray);
return resultArray;
});
//# sourceMappingURL=data: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QUFDO0lBQ3RDLElBQUksV0FBVyxHQUFHLEVBQUUsQ0FBQztJQUNyQixLQUFLLElBQUksSUFBSSxJQUFJLFFBQVEsRUFBRTtRQUN6QixJQUFJLE9BQU8sR0FBaUIsV0FBVyxDQUFDLElBQUksQ0FBQyxDQUFDO1FBQzlDLFlBQVksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDM0IsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUFDLENBQUMsRUFBRTtZQUNmLFdBQVcsQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDdEIsQ0FBQyxDQUFDLENBQUM7S0FDSjtJQUNELE1BQU0sT0FBTyxDQUFDLEdBQUcsQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUNoQyxPQUFPLFdBQVcsQ0FBQztBQUNyQixDQUFDLENBQUMifQ==
{
"npmci": {
"npmGlobalTools": [
"npmts"
],
"npmGlobalTools": [],
"npmAccessLevel": "public"

@@ -7,0 +5,0 @@ },

{
"name": "@pushrocks/smartpromise",
"private": false,
"version": "3.0.2",
"version": "3.0.5",
"description": "simple promises and Deferred constructs",

@@ -9,4 +9,4 @@ "main": "dist/index.js",

"scripts": {
"test": "(tsrun test/test.ts)",
"build": "(npmts)"
"test": "(tstest test/)",
"build": "(tsbuild)"
},

@@ -25,6 +25,20 @@ "repository": {

"devDependencies": {
"@gitzone/tsrun": "^1.0.18",
"@types/node": "^10.5.1",
"tapbundle": "^2.0.0"
}
"@gitzone/tsbuild": "^2.1.17",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.7.5",
"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"
]
}
# @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)

@@ -26,3 +29,3 @@ [![coverage report](https://gitlab.com/pushrocks/smartpromise/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartpromise/commits/master)

```javascript
```typescript
import * as q from '@pushrocks/smartpromise'

@@ -33,7 +36,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)
return done.promise
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);
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
}

@@ -80,4 +90,4 @@

> MIT licensed | **&copy;** [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)
export interface IResolve<T> {
(value?: T | Promise<T>): void;
(value?: T | PromiseLike<T>): void;
}

@@ -12,10 +12,30 @@

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';

@@ -22,0 +42,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc