-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
5,208 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2021": true, | ||
"node": true, | ||
"jest": true | ||
}, | ||
"extends": [ | ||
"plugin:react/recommended", | ||
"standard" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"ecmaVersion": 12, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"react", | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
# monoclean | ||
|
||
node_modules | ||
.nvm.rc | ||
package.json | ||
package-lock.json | ||
yarn-lock.* | ||
yarn.lock | ||
tsconfig.** | ||
jest.config.js | ||
yarn-error.log | ||
tmp | ||
out | ||
.eslintrc.json | ||
dist | ||
coverage | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"redhat.vscode-yaml" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"search.exclude": { | ||
"**/node_modules": true, | ||
"**/bower_components": true, | ||
"**/env": true, | ||
"**/venv": true | ||
}, | ||
"files.watcherExclude": { | ||
"**/.git/objects/**": true, | ||
"**/.git/subtree-cache/**": true, | ||
"**/node_modules/**": true, | ||
"**/env/**": true, | ||
"**/venv/**": true, | ||
"env-*": true | ||
}, | ||
"yaml.schemas": { | ||
"https://teintinu.github.io/monoclean/monoclean-schema.json": [ | ||
"monoclean.yml" | ||
] | ||
}, | ||
"typescript.disableAutomaticTypeAcquisition": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,57 @@ | ||
# pjobs | ||
Efficient promise queue job manager | ||
A simple and efficient queue job executor using promises. And some promise's utilities. | ||
|
||
# install | ||
|
||
```bash | ||
npm install --save pjobs | ||
``` | ||
|
||
# usage | ||
|
||
## `queuePromises` | ||
defines an executor for jobs. A job is just a function that returns a Promise. You can also control concurrency and promises. | ||
```typescript | ||
import { queuePromises } from 'pjobs' | ||
const queue = queuePromises({ | ||
concurrency: 1, // maximum of promises running concurrently | ||
onProgress (status) { // allow you to inform users about execution progress | ||
console.log('queue status: ', status) | ||
} | ||
}) | ||
queue.enqueue(async () => { // add a job to the queue | ||
console.log('task 1') | ||
}) | ||
queue.enqueue(async () => { // add another job to the queue | ||
console.log('task 2') | ||
}) | ||
|
||
await queue.waitFor() // wait for all jobs to be finished. | ||
``` | ||
|
||
## `defer` | ||
allow you to defer promise's resolving or rejecting. | ||
|
||
```typescript | ||
import { queuePromises, defer } from 'pjobs' | ||
const taskOne = defer<void>() // defines the deferred promise | ||
const queue = queuePromises() | ||
queue.enqueue(async () => { | ||
console.log('task 1') | ||
taskOne.resolve() // resolves the deferred promise | ||
}) | ||
queue.enqueue(async () => { | ||
console.log('task 2') | ||
}) | ||
expect(queue.state()).not.toBe('idle') | ||
await taskOne.promise // wait for the deferred promise to be resolved | ||
await queue.waitFor() | ||
``` | ||
|
||
## `sleep` | ||
allow you pause execution flow for some miliseconds | ||
|
||
```typescript | ||
import { sleep } from 'pjobs' | ||
await sleep(100) // pause execution flow for 100 miliseconds | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { pathsToModuleNameMapper } = require('ts-jest/utils') | ||
const { compilerOptions } = require('./tsconfig.test') | ||
|
||
const moduleNameMapper = pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }) | ||
|
||
module.exports = { | ||
preset: 'ts-jest', | ||
modulePathIgnorePatterns: ['dist'], | ||
testPathIgnorePatterns: ['node_modules', 'dist'], | ||
testRegex: '(\\.(test|spec|steps))\\.(ts|tsx)$', | ||
globals: { | ||
'ts-jest': { | ||
tsConfig: 'tsconfig.test.json' | ||
} | ||
}, | ||
moduleNameMapper, | ||
transform: { | ||
'^.+\\.tsx?$': [ | ||
'esbuild-jest', | ||
{ | ||
sourcemap: 'inline', | ||
target: ['es6','node12'], | ||
loaders: { | ||
'.spec.ts': 'tsx', | ||
'.test.ts': 'tsx', | ||
'.steps.ts': 'tsx', | ||
} | ||
} | ||
] | ||
}, | ||
coverageReporters: [ | ||
'text', | ||
'html', | ||
'cobertura', | ||
'json-summary' | ||
], | ||
coverageThreshold: { | ||
global: { | ||
lines: 90, | ||
statements: 90, | ||
functions: 90, | ||
branches: 90 | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "pjobs", | ||
"description": "A simple and efficient queue job executor using promises. And some promise's utilities.", | ||
"version": "1.0.1", | ||
"private": true, | ||
"devDependencies": { | ||
"@types/jest": "^27.0.2", | ||
"@types/source-map-support": "^0.5.4", | ||
"@typescript-eslint/eslint-plugin": "^5.2.0", | ||
"@typescript-eslint/parser": "^5.2.0", | ||
"dts-bundle-generator": "^5.9.0", | ||
"esbuild": "^0.13.9", | ||
"esbuild-jest": "^0.5.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-standard": "^16.0.3", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-promise": "^5.1.1", | ||
"eslint-plugin-react": "^7.26.1", | ||
"jest": "^27.3.1", | ||
"source-map-support": "^0.5.20", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.4.4" | ||
}, | ||
"scripts": { | ||
"build": "monoclean build", | ||
"clean": "monoclean clean", | ||
"publish": "monoclean publish", | ||
"start": "monoclean run", | ||
"tsc-watch": "tsc -p . --watch" | ||
}, | ||
"workspaces": [ | ||
"package" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src | ||
*.map | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# pjobs | ||
A simple and efficient queue job executor using promises. And some promise's utilities. | ||
|
||
# install | ||
|
||
```bash | ||
npm install --save pjobs | ||
``` | ||
|
||
# usage | ||
|
||
## `queuePromises` | ||
defines an executor for jobs. A job is just a function that returns a Promise. You can also control concurrency and promises. | ||
```typescript | ||
import { queuePromises } from 'pjobs' | ||
const queue = queuePromises({ | ||
concurrency: 1, // maximum of promises running concurrently | ||
onProgress (status) { // allow you to inform users about execution progress | ||
console.log('queue status: ', status) | ||
} | ||
}) | ||
queue.enqueue(async () => { // add a job to the queue | ||
console.log('task 1') | ||
}) | ||
queue.enqueue(async () => { // add another job to the queue | ||
console.log('task 2') | ||
}) | ||
|
||
await queue.waitFor() // wait for all jobs to be finished. | ||
``` | ||
|
||
## `defer` | ||
allow you to defer promise's resolving or rejecting. | ||
|
||
```typescript | ||
import { queuePromises, defer } from 'pjobs' | ||
const taskOne = defer<void>() // defines the deferred promise | ||
const queue = queuePromises() | ||
queue.enqueue(async () => { | ||
console.log('task 1') | ||
taskOne.resolve() // resolves the deferred promise | ||
}) | ||
queue.enqueue(async () => { | ||
console.log('task 2') | ||
}) | ||
expect(queue.state()).not.toBe('idle') | ||
await taskOne.promise // wait for the deferred promise to be resolved | ||
await queue.waitFor() | ||
``` | ||
|
||
## `sleep` | ||
allow you pause execution flow for some miliseconds | ||
|
||
```typescript | ||
import { sleep } from 'pjobs' | ||
await sleep(100) // pause execution flow for 100 miliseconds | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "pjobs", | ||
"description": "A simple and efficient queue job executor using promises. And some promise's utilities.", | ||
"version": "1.0.1", | ||
"private": false, | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"devDependencies": { | ||
"@types/jest": "^27.0.2", | ||
"@types/source-map-support": "^0.5.4", | ||
"dts-bundle-generator": "^5.9.0", | ||
"esbuild": "^0.13.9", | ||
"esbuild-jest": "^0.5.0", | ||
"jest": "^27.3.1", | ||
"source-map-support": "^0.5.20", | ||
"ts-jest": "^27.0.7", | ||
"typescript": "^4.4.4" | ||
}, | ||
"scripts": { | ||
"buildDTS": "dts-bundle-generator --project ./tsconfig.build.json --verbose", | ||
"buildWithTSC": "tsc -p ./tsconfig.build.json", | ||
"prepublish": "yarn test && yarn buildWithTSC", | ||
"test": "jest --config ../jest.config.js .", | ||
"clean": "monoclean clean" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.