Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added doctor + test script #2

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ dist
*.sln
*.sw?

coverage
coverage

.clinic
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.git
.gitignore
demo
coverage
coverage
.clinic
doctor-patient.js
20 changes: 20 additions & 0 deletions doctor-patient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { cacheCandidate } = require('./dist/index.js');
let counter = 0;
const mockFn = (step) =>
new Promise((resolve) => {
counter += step;
resolve(counter);
});
const wrappedMockFn = cacheCandidate(mockFn, {
requestsThreshold: 1,
ttl: 800,
keepAlive: false,
});
(async () => {
let result = await wrappedMockFn(1);
console.log(result); // 1
result = await wrappedMockFn(1);
console.log(result); // 1
result = await wrappedMockFn(1);
console.log(result); // 1
})();
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ts-types": " tsc --emitDeclarationOnly --outDir dist",
"check": "npm run prettier && npm run lint && npm test",
"build": "npm run check && rimraf dist && NODE_ENV=production node esbuild.js && npm run ts-types",
"build-doctor-bubbleproof": "rimraf dist && NODE_ENV=development node esbuild.js && npx clinic bubbleproof -- node ./doctor-patient.js",
"demo-test": "for file in demo/*.js; do node $file; done",
"prettier": "prettier --write ./src",
"lint": "eslint ./src --ext .ts",
Expand Down