Skip to content

Commit

Permalink
Release 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysedoy97 committed Mar 15, 2022
1 parent ba828ed commit 18c1a4b
Show file tree
Hide file tree
Showing 19 changed files with 4,538 additions and 301 deletions.
2 changes: 1 addition & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name = "javascript"
enabled = true

[analyzers.meta]
environment = ["browser", "nodejs"]
environment = ["nodejs"]
module_system = "es-modules"

[[transformer]]
Expand Down
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,json,toml}]
[*.{js,json,toml,yaml,yml,html,md}]
charset = utf-8
indent_size = 2
indent_style = space
26 changes: 19 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"extends": ["eslint:recommended", "plugin:node/recommended", "prettier"],
"env": {
"browser": true,
"es2021": true,
"es2022": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:node/recommended", "plugin:github/recommended", "plugin:sonarjs/recommended", "prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"ecmaFeatures": {
"impliedStrict": true
}
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["node", "github", "sonarjs"],
"rules": {
"arrow-body-style": ["warn", "always"],
"camelcase": "warn",
Expand All @@ -20,22 +20,29 @@
"default-case-last": "warn",
"dot-notation": "warn",
"eqeqeq": "warn",
"eslint-comments/no-use": "off",
"filenames/match-regex": "off",
"i18n-text/no-en": "off",
"import/extensions": ["warn", "always"],
"import/no-unresolved": "off",
"no-duplicate-imports": "warn",
"no-lonely-if": "warn",
"no-return-assign": "warn",
"no-return-await": "warn",
"no-unused-vars": "warn",
"no-use-before-define": "warn",
"no-var": "warn",
"node/exports-style": ["warn", "module.exports"],
"node/file-extension-in-import": ["warn", "always"],
"node/no-missing-import": "off",
"node/no-unsupported-features/es-syntax": "warn",
"node/prefer-global/buffer": ["warn", "always"],
"node/prefer-global/console": ["warn", "always"],
"node/prefer-global/process": ["warn", "always"],
"node/prefer-global/text-decoder": ["warn", "always"],
"node/prefer-global/text-encoder": ["warn", "always"],
"node/prefer-global/url-search-params": ["warn", "always"],
"node/prefer-global/url": ["warn", "always"],
"node/prefer-global/url-search-params": ["warn", "always"],
"node/prefer-promises/dns": "warn",
"node/prefer-promises/fs": "warn",
"object-shorthand": "warn",
Expand All @@ -44,6 +51,11 @@
"prefer-rest-params": "warn",
"prefer-spread": "warn",
"require-await": "warn",
"sonarjs/cognitive-complexity": "off",
"sonarjs/no-duplicate-string": "warn",
"sonarjs/no-identical-functions": "warn",
"sonarjs/no-nested-switch": "off",
"sonarjs/no-small-switch": "warn",
"sort-imports": "warn",
"sort-keys": "warn",
"sort-vars": "warn"
Expand Down
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* text=auto

*.js text eol=lf
*.json text eol=lf
*.toml text eol=lf
*.yaml text eol=lf
*.yml text eol=lf
*.html text eol=lf
*.md text eol=lf
19 changes: 4 additions & 15 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
---
jobs:
publish-github:
needs: test
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://npm.pkg.github.com/
- env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: npm publish
publish-npm:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
run: npm publish
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- run: npm ci --no-audit --ignore-scripts
- run: npm test
name: npm-publish
'on':
release:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/npm-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm ci --ignore-scripts
- run: npm test
strategy:
matrix:
node-version:
- 12
- 14
- 16
name: npm-test
'on': push
10 changes: 6 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/sh
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

volta run eslint --fix .
volta run prettier --write .
npm install --ignore-scripts --no-audit --no-fund
npm test
volta run --node 16 --bundled-npm -- npm install --ignore-scripts
volta run --node 16 --bundled-npm -- npm test
volta run --node 14 --bundled-npm -- npm test
volta run --node 12 --bundled-npm -- npm test
cd example
npm install --ignore-scripts --no-audit --no-fund
volta run --node 16 --bundled-npm -- npm install
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
audit = false
fund = false
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"recommendations": [
"aaron-bond.better-comments",
"amatiasq.sort-imports",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"mgmcdermott.vscode-language-babel",
"sonarsource.sonarlint-vscode",
"visualstudioexptteam.vscodeintellicode"
]
}
8 changes: 4 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"editor.autoClosingQuotes": "always",
"editor.autoIndent": "full",
"editor.autoSurround": "languageDefined",
"editor.bracketPairColorization.enabled": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.foldingImportsByDefault": true,
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.renderWhitespace": "all",
"editor.suggestSelection": "first",
"editor.tabSize": 2,
"eslint.format.enable": true,
Expand All @@ -15,8 +18,5 @@
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"git.autofetch": true,
"git.confirmSync": false,
"telemetry.enableCrashReporter": false,
"telemetry.enableTelemetry": false,
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue"
"git.confirmSync": false
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 sergeysedoy97
Copyright (c) 2022 sergeysedoy97

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
75 changes: 35 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,49 @@

---

## Example

Full example in `/example` folder.
## Install

```sh
npm install @awesomeorganization/promise-queue
```
import { promiseQueue } from '@awesomeorganization/promise-queue'
import { request } from 'undici'

const example = async () => {
const { push } = promiseQueue({
concurrency: 2,
})
const time = Date.now()
const [
{
headers: { date: dateA },
},
{
headers: { date: dateB },
},
{
headers: { date: dateC },
},
] = await Promise.all([
push(() => {
return request('https://httpbin.org/delay/1')
}),
push(() => {
return request('https://httpbin.org/delay/1')
}),
push(() => {
return request('https://httpbin.org/delay/1')
}),
])
console.dir({
dateA,
dateB,
dateC,
duration: Math.round((Date.now() - time) / 1000),
})
}
## Example

example()
Full example in `/example` folder.

```js
const { push } = promiseQueue({
concurrency: 2,
})
const [
{
headers: { date: dateA },
},
{
headers: { date: dateB },
},
{
headers: { date: dateC },
},
] = await Promise.all([
push(() => {
return request('https://httpbin.org/delay/1')
}),
push(() => {
return request('https://httpbin.org/delay/1')
}),
push(() => {
return request('https://httpbin.org/delay/1')
}),
])
console.dir({
dateA,
dateB,
dateC,
})
// {
// dateA: 'Wed, 26 Jan 2022 20:00:01 GMT',
// dateB: 'Wed, 26 Jan 2022 20:00:02 GMT',
// dateC: 'Wed, 26 Jan 2022 20:00:02 GMT',
// duration: 3
// }
```
3 changes: 1 addition & 2 deletions example/example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable node/no-unsupported-features/es-syntax */

import { promiseQueue } from '@awesomeorganization/promise-queue'
import { request } from 'undici'

Expand Down Expand Up @@ -29,6 +27,7 @@ const example = async () => {
return request('https://httpbin.org/delay/1')
}),
])
// eslint-disable-next-line no-console
console.dir({
dateA,
dateB,
Expand Down
10 changes: 7 additions & 3 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/* eslint-disable github/no-then */

const DEFAULT_CONCURRENCY = 1

Expand All @@ -24,6 +24,7 @@ export const promiseQueue = ({ concurrency = DEFAULT_CONCURRENCY } = { concurren
})
)
.then((values) => {
// eslint-disable-next-line github/array-foreach
values.forEach((iterator, index) => {
iterator.status === 'fulfilled' ? slice[index][1](iterator.value) : slice[index][2](iterator.reason)
})
Expand Down

0 comments on commit 18c1a4b

Please sign in to comment.