promised-map
Advanced tools
{ | ||
"name": "promised-map", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A map of promises that can be resolved or rejected by key", | ||
@@ -17,11 +17,8 @@ "author": { | ||
"main": "src/index.js", | ||
"browser": "dist/bundle.js", | ||
"scripts": { | ||
"lint": "eslint src test", | ||
"build": "rollup -c", | ||
"test": "mocha test/setup.js test/specs", | ||
"test:bundle": "LIB_PATH=../dist/bundle.js npm t", | ||
"ci": "run-s lint build test test:bundle", | ||
"test": "mocha test/setup test/specs", | ||
"ci": "npm run lint && npm test", | ||
"toc": "markdown-toc README.md -i", | ||
"prerelease": "run-s lint build test test:bundle", | ||
"prerelease": "npm run lint && npm test", | ||
"release": "npm version $VER && npm publish", | ||
@@ -35,3 +32,3 @@ "postrelease": "git push --follow-tags --no-verify", | ||
"pre-commit": "lint-staged && npm test", | ||
"pre-push": "run-s lint test" | ||
"pre-push": "npm run lint && npm test" | ||
} | ||
@@ -43,18 +40,10 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.6.4", | ||
"@babel/preset-env": "^7.6.3", | ||
"assert-rejects": "^1.0.0", | ||
"chai": "^4.2.0", | ||
"eslint": "^6.5.1", | ||
"eslint-plugin-mocha": "^6.2.0", | ||
"eslint": "^6.6.0", | ||
"eslint-plugin-mocha": "^6.2.1", | ||
"husky": "^3.0.9", | ||
"lint-staged": "^9.4.2", | ||
"markdown-toc": "^1.2.0", | ||
"mocha": "^6.2.2", | ||
"npm-run-all": "^4.1.5", | ||
"rollup": "^1.25.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-banner": "^0.2.1", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-delete": "^1.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0" | ||
"mocha": "^6.2.2" | ||
}, | ||
@@ -66,6 +55,3 @@ "keywords": [ | ||
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"promise-controller": "^0.6.0" | ||
} | ||
"license": "MIT" | ||
} |
@@ -24,17 +24,16 @@ # promised-map | ||
```js | ||
const EventEmitter = require('events'); | ||
const PromisedMap = require('promised-map'); | ||
const emitter = new EventEmitter(); | ||
const map = new PromisedMap(); | ||
async function sendRequestAndWaitResponse(request) { | ||
emitter.dispatch(request); | ||
await map.wait(request.id); | ||
} | ||
const promise = map.wait('foo'); | ||
emitter.on('response', response => map.resolve(response.id, response)); | ||
// resolve by key | ||
map.resolve('foo', 42); | ||
sendRequestAndWaitResponse({id: '1', payload: 'foo'}); // => resolves when response arrives | ||
// reject by key | ||
map.reject('foo', new Error('error')); | ||
// check is promise still pending | ||
map.has('foo'); | ||
``` | ||
@@ -41,0 +40,0 @@ |
@@ -15,4 +15,8 @@ /** | ||
wait(key) { | ||
return new Promise((resolve, reject) => { | ||
let {promise} = this._map.get(key) || {}; | ||
if (!promise) { | ||
let resolve, reject; | ||
promise = new Promise((res, rej) => [resolve, reject] = [res, rej]); | ||
this._map.set(key, { | ||
promise, | ||
resolve, | ||
@@ -22,3 +26,4 @@ reject, | ||
}); | ||
}); | ||
} | ||
return promise; | ||
} | ||
@@ -25,0 +30,0 @@ |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
0
-100%8
-50%0
-100%3279
-55.38%3
-57.14%57
-70.31%42
-2.33%