auto-reset-event 1.1.1-master.5c3023c → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) William Wong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -15,7 +15,7 @@ Run `npm install auto-reset-event`.
15
15
  ## Code snippets
16
16
 
17
17
  ```js
18
- import createAutoResetEvent from 'auto-reset-event';
18
+ import { createAutoResetEvent } from 'auto-reset-event';
19
19
 
20
20
  // Create an acquire-release queue
21
21
  const acquire = createAutoResetEvent();
@@ -32,7 +32,7 @@ release();
32
32
  ## Full sample
33
33
 
34
34
  ```js
35
- import createAutoResetEvent from 'auto-reset-event';
35
+ import { createAutoResetEvent } from 'auto-reset-event';
36
36
  import delay from 'delay';
37
37
 
38
38
  async function main() {
@@ -73,7 +73,7 @@ We can use `auto-reset-event` to easily slow down concurrent requests by limitin
73
73
 
74
74
  ```js
75
75
  import { createServer } from 'restify';
76
- import createAutoResetEvent from 'auto-reset-event';
76
+ import { createAutoResetEvent } from 'auto-reset-event';
77
77
  import delay from 'delay';
78
78
  import serveHandler from 'serve-handler';
79
79
 
@@ -0,0 +1,3 @@
1
+ declare function createAutoResetEvent(): () => Promise<() => void>;
2
+
3
+ export { createAutoResetEvent };
@@ -0,0 +1,3 @@
1
+ declare function createAutoResetEvent(): () => Promise<() => void>;
2
+
3
+ export { createAutoResetEvent };
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ createAutoResetEvent: () => createAutoResetEvent
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/createAutoResetEvent.ts
28
+ function createAutoResetEvent() {
29
+ const queue = [];
30
+ const release = () => {
31
+ queue.shift();
32
+ queue[0] && queue[0].resolve(release);
33
+ };
34
+ return () => {
35
+ const resolvers = Promise.withResolvers();
36
+ queue.push(resolvers);
37
+ if (queue[0] === resolvers) {
38
+ resolvers.resolve(release);
39
+ }
40
+ return resolvers.promise;
41
+ };
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ createAutoResetEvent
46
+ });
47
+ //# sourceMappingURL=auto-reset-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/createAutoResetEvent.ts"],"sourcesContent":["export { default as createAutoResetEvent } from './createAutoResetEvent.ts';\n","export default function createAutoResetEvent() {\n const queue: PromiseWithResolvers<() => void>[] = [];\n const release = () => {\n queue.shift();\n\n queue[0] && queue[0].resolve(release);\n };\n\n return () => {\n const resolvers = Promise.withResolvers<() => void>();\n\n queue.push(resolvers);\n\n if (queue[0] === resolvers) {\n resolvers.resolve(release);\n }\n\n return resolvers.promise;\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAe,SAAR,uBAAwC;AAC7C,QAAM,QAA4C,CAAC;AACnD,QAAM,UAAU,MAAM;AACpB,UAAM,MAAM;AAEZ,UAAM,CAAC,KAAK,MAAM,CAAC,EAAE,QAAQ,OAAO;AAAA,EACtC;AAEA,SAAO,MAAM;AACX,UAAM,YAAY,QAAQ,cAA0B;AAEpD,UAAM,KAAK,SAAS;AAEpB,QAAI,MAAM,CAAC,MAAM,WAAW;AAC1B,gBAAU,QAAQ,OAAO;AAAA,IAC3B;AAEA,WAAO,UAAU;AAAA,EACnB;AACF;","names":[]}
@@ -0,0 +1,20 @@
1
+ // src/createAutoResetEvent.ts
2
+ function createAutoResetEvent() {
3
+ const queue = [];
4
+ const release = () => {
5
+ queue.shift();
6
+ queue[0] && queue[0].resolve(release);
7
+ };
8
+ return () => {
9
+ const resolvers = Promise.withResolvers();
10
+ queue.push(resolvers);
11
+ if (queue[0] === resolvers) {
12
+ resolvers.resolve(release);
13
+ }
14
+ return resolvers.promise;
15
+ };
16
+ }
17
+ export {
18
+ createAutoResetEvent
19
+ };
20
+ //# sourceMappingURL=auto-reset-event.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/createAutoResetEvent.ts"],"sourcesContent":["export default function createAutoResetEvent() {\n const queue: PromiseWithResolvers<() => void>[] = [];\n const release = () => {\n queue.shift();\n\n queue[0] && queue[0].resolve(release);\n };\n\n return () => {\n const resolvers = Promise.withResolvers<() => void>();\n\n queue.push(resolvers);\n\n if (queue[0] === resolvers) {\n resolvers.resolve(release);\n }\n\n return resolvers.promise;\n };\n}\n"],"mappings":";AAAe,SAAR,uBAAwC;AAC7C,QAAM,QAA4C,CAAC;AACnD,QAAM,UAAU,MAAM;AACpB,UAAM,MAAM;AAEZ,UAAM,CAAC,KAAK,MAAM,CAAC,EAAE,QAAQ,OAAO;AAAA,EACtC;AAEA,SAAO,MAAM;AACX,UAAM,YAAY,QAAQ,cAA0B;AAEpD,UAAM,KAAK,SAAS;AAEpB,QAAI,MAAM,CAAC,MAAM,WAAW;AAC1B,gBAAU,QAAQ,OAAO;AAAA,IAC3B;AAEA,WAAO,UAAU;AAAA,EACnB;AACF;","names":[]}
package/package.json CHANGED
@@ -1,17 +1,43 @@
1
1
  {
2
2
  "name": "auto-reset-event",
3
- "version": "1.1.1-master.5c3023c",
3
+ "version": "2.0.0",
4
4
  "description": "An acquire-release one semantic implemented in Promise.",
5
- "main": "lib/index.js",
5
+ "files": [
6
+ "./*.js",
7
+ "./dist/"
8
+ ],
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/auto-reset-event.d.mts",
13
+ "default": "./dist/auto-reset-event.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/auto-reset-event.d.ts",
17
+ "default": "./dist/auto-reset-event.js"
18
+ }
19
+ }
20
+ },
21
+ "main": "./dist/auto-reset-event.js",
22
+ "typings": "./dist/auto-reset-event.d.ts",
6
23
  "scripts": {
7
- "build": "babel --out-dir lib src --ignore **/*.spec.js,**/*.test.js",
8
- "prestart": "npm run build:babel",
9
- "start": "npm run build:babel -- --skip-initial-build --watch",
10
- "test": "jest --collectCoverage true"
24
+ "build": "tsup",
25
+ "bump": "npm run bump:prod && npm run bump:dev",
26
+ "bump:dev": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.devDependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
27
+ "bump:prod": "PACKAGES_TO_BUMP=$(cat package.json | jq -r '(.pinDependencies // {}) as $P | (.localPeerDependencies // {}) as $L | (.dependencies // {}) | to_entries | map(select(.key as $K | $L | has($K) | not)) | map(.key + \"@\" + ($P[.key] // [\"latest\"])[0]) | join(\" \")') && [ ! -z \"$PACKAGES_TO_BUMP\" ] && npm install $PACKAGES_TO_BUMP || true",
28
+ "precommit": "npm run precommit:eslint && npm run precommit:publint && npm run precommit:typescript:production && npm run precommit:typescript:test",
29
+ "precommit:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint ./src/",
30
+ "precommit:publint": "publint",
31
+ "precommit:typescript:production": "tsc --noEmit --project ./src/tsconfig.precommit.production.json",
32
+ "precommit:typescript:test": "tsc --noEmit --project ./src/tsconfig.precommit.test.json",
33
+ "prepack": "cp ../../CHANGELOG.md . && cp ../../LICENSE . && cp ../../README.md .",
34
+ "start": "npm run build -- --onSuccess \"touch ../pages/package.json\" --watch",
35
+ "switch": "cat package.json | jq --arg SWITCH_NAME $SWITCH_NAME -r '(.[\"switch:\" + $SWITCH_NAME] // {}) as $TEMPLATE | .devDependencies += ($TEMPLATE.devDependencies // {}) | .dependencies += ($TEMPLATE.dependencies // {})' | tee ./package.json.tmp && mv ./package.json.tmp ./package.json",
36
+ "test": "node --test ${CI:---watch} **/*.{spec,test}.{[jt]s,[jt]sx,c[jt]s,m[jt]s}"
11
37
  },
12
38
  "repository": {
13
39
  "type": "git",
14
- "url": "git+https://github.com/compulim/auto-reset-event.git"
40
+ "url": "https://github.com/compulim/auto-reset-event.git"
15
41
  },
16
42
  "keywords": [
17
43
  "auto reset event",
@@ -24,22 +50,17 @@
24
50
  "url": "https://github.com/compulim/auto-reset-event/issues"
25
51
  },
26
52
  "homepage": "https://github.com/compulim/auto-reset-event#readme",
27
- "dependencies": {
28
- "@babel/runtime": "7.9.6",
29
- "p-defer": "3.0.0",
30
- "p-defer-es5": "1.0.1"
31
- },
32
53
  "devDependencies": {
33
- "@babel/cli": "^7.8.4",
34
- "@babel/core": "^7.9.6",
35
- "@babel/plugin-proposal-object-rest-spread": "^7.9.6",
36
- "@babel/plugin-transform-runtime": "^7.5.5",
37
- "@babel/preset-env": "^7.9.6",
38
- "babel-jest": "^26.0.1",
39
- "babel-plugin-add-module-exports": "^1.0.2",
40
- "delay": "^4.3.0",
41
- "has-resolved": "^1.1.0",
42
- "jest": "^26.0.1",
43
- "regenerator-runtime": "^0.13.5"
54
+ "@tsconfig/recommended": "^1.0.13",
55
+ "@tsconfig/strictest": "^2.0.8",
56
+ "@types/node": "^25.0.3",
57
+ "expect": "^30.2.0",
58
+ "has-resolved": "^2.0.0",
59
+ "publint": "^0.3.16",
60
+ "tsup": "^8.5.1",
61
+ "typescript": "^5.9.3"
62
+ },
63
+ "dependencies": {
64
+ "auto-reset-event": "^2.0.0"
44
65
  }
45
66
  }
@@ -1,92 +0,0 @@
1
- # This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
-
4
- name: Node.js CI
5
-
6
- on:
7
- push:
8
- branches:
9
- - master
10
- tags:
11
- - '*'
12
-
13
- pull_request:
14
- branches:
15
- - master
16
-
17
- jobs:
18
- build:
19
- runs-on: ubuntu-latest
20
-
21
- strategy:
22
- matrix:
23
- node-version: [12.x, 14.x]
24
-
25
- steps:
26
- - name: Checking out for ${{ github.ref }}
27
- uses: actions/checkout@v2
28
-
29
- - name: Use Node.js ${{ matrix.node-version }}
30
- uses: actions/setup-node@v1
31
- with:
32
- node-version: ${{ matrix.node-version }}
33
-
34
- - run: npx version-from-git --no-git-tag-version
35
- if: ${{ startsWith(github.ref, 'refs/heads/') }}
36
-
37
- - run: npm ci
38
-
39
- - run: npm run build --if-present
40
-
41
- - run: npm test
42
-
43
- - run: npm pack
44
-
45
- - uses: actions/upload-artifact@v2
46
- if: ${{ matrix.node-version == '14.x' }}
47
- with:
48
- name: npm-tarball
49
- path: '*.tgz'
50
-
51
- publish:
52
- needs: build
53
- runs-on: ubuntu-latest
54
- if: ${{ startsWith(github.ref, 'refs/heads/') || startsWith(github.ref, 'refs/tags/') }}
55
-
56
- steps:
57
- - uses: actions/download-artifact@v2
58
- with:
59
- name: npm-tarball
60
-
61
- - name: Read package.json
62
- id: read-package-json
63
- run: |
64
- echo "::set-output name=name::$(tar xOf *.tgz package/package.json | jq -r '.name')"
65
- echo "::set-output name=version::$(tar xOf *.tgz package/package.json | jq -r '.version')"
66
- echo "::set-output name=tarball::$(ls *.tgz)"
67
- echo "::set-output name=date::$(date +%Y-%m-%d)"
68
-
69
- - name: Run npm publish ${{ steps.read-package-json.outputs.name }}@${{ steps.read-package-json.outputs.version }}
70
- run: |
71
- npm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
72
- npm publish *.tgz --tag master
73
-
74
- - uses: actions/create-release@v1
75
- id: create-release
76
- if: ${{ startsWith(github.ref, 'refs/tags/') }}
77
- env:
78
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79
- with:
80
- tag_name: ${{ github.ref }}
81
- release_name: '[${{ steps.read-package-json.outputs.version }}] - ${{ steps.read-package-json.outputs.date }}'
82
- draft: true
83
-
84
- - uses: actions/upload-release-asset@v1
85
- if: ${{ startsWith(github.ref, 'refs/tags/') }}
86
- env:
87
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88
- with:
89
- upload_url: ${{ steps.create-release.outputs.upload_url }}
90
- asset_path: ./${{ steps.read-package-json.outputs.tarball }}
91
- asset_name: ${{ steps.read-package-json.outputs.tarball }}
92
- asset_content_type: application/octet-stream
package/CHANGELOG.md DELETED
@@ -1,45 +0,0 @@
1
- # Changelog
2
-
3
- All notable changes to this project will be documented in this file.
4
-
5
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
-
8
- ## [Unreleased]
9
-
10
- ## [1.1.0] - 2020-05-26
11
-
12
- ### Changed
13
-
14
- - Bump dependencies, in PR [#5](https://github.com/compulim/auto-reset-event/pull/5)
15
- - [`@babel/cli@7.8.4`](https://npmjs.com/package/@babel/cli)
16
- - [`@babel/core@7.9.6`](https://npmjs.com/package/@babel/core)
17
- - [`@babel/plugin-proposal-object-rest-spread@7.9.6`](https://npmjs.com/package/@babel/plugin-proposal-object-rest-spread)
18
- - [`@babel/plugin-transform-runtime@7.5.5`](https://npmjs.com/package/@babel/plugin-transform-runtime)
19
- - [`@babel/preset-env@7.9.6`](https://npmjs.com/package/@babel/preset-env)
20
- - [`@babel/runtime@7.9.6`](https://npmjs.com/package/@babel/runtime)
21
- - [`babel-jest@26.0.1`](https://npmjs.com/package/babel-jest)
22
- - [`babel-plugin-add-module-exports@1.0.2`](https://npmjs.com/package/babel-plugin-add-module-exports)
23
- - [`delay@4.3.0`](https://npmjs.com/package/delay)
24
- - [`has-resolved@1.1.0`](https://npmjs.com/package/has-resolved)
25
- - [`jest@26.0.1`](https://npmjs.com/package/jest)
26
- - [`p-defer-es5@1.0.1`](https://npmjs.com/package/p-defer-es5)
27
- - [`p-defer@3.0.0`](https://npmjs.com/package/p-defer)
28
- - [`regenerator-runtime@0.13.5`](https://npmjs.com/package/regenerator-runtime)
29
-
30
- - Bump dependencies, in PR [#1](https://github.com/compulim/auto-reset-event/pull/1)
31
- - [@babel/cli@^7.5.5](https://www.npmjs.com/package/@babel/cli)
32
- - [@babel/core@^7.5.5](https://www.npmjs.com/package/@babel/core)
33
- - [@babel/plugin-transform-runtime@^7.5.5](https://www.npmjs.com/package/@babel/plugin-transform-runtime)
34
- - [@babel/preset-env@^7.5.5](https://www.npmjs.com/package/@babel/preset-env)
35
- - [babel-jest@^24.8.0](https://www.npmjs.com/package/babel-jest)
36
- - [delay@^4.3.0](https://www.npmjs.com/package/delay)
37
- - [has-resolved@^1.1.0](https://www.npmjs.com/package/has-resolved)
38
- - [jest@^24.8.0](https://www.npmjs.com/package/jest)
39
- - [regenerator-runtime@^0.13.2](https://www.npmjs.com/package/regenerator-runtime)
40
-
41
- ## [1.0.0] - 2018-10-03
42
-
43
- ### Added
44
-
45
- - Initial public release
package/babel.config.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "plugins": [
3
- "@babel/plugin-transform-runtime"
4
- ],
5
- "presets": [
6
- [
7
- "@babel/preset-env",
8
- {
9
- "targets": {
10
- "node": "10"
11
- },
12
- "forceAllTransforms": true
13
- }
14
- ]
15
- ]
16
- }
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _pDeferEs = _interopRequireDefault(require("p-defer-es5"));
11
-
12
- var _default = function _default() {
13
- var queue = [];
14
-
15
- var release = function release() {
16
- queue.shift();
17
- queue[0] && queue[0].resolve(release);
18
- };
19
-
20
- return function () {
21
- var deferred = (0, _pDeferEs["default"])();
22
- queue.push(deferred);
23
-
24
- if (queue[0] === deferred) {
25
- deferred.resolve(release);
26
- }
27
-
28
- return deferred.promise;
29
- };
30
- };
31
-
32
- exports["default"] = _default;
package/lib/index.js DELETED
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _createAutoResetEvent = _interopRequireDefault(require("./createAutoResetEvent"));
11
-
12
- var _default = _createAutoResetEvent["default"];
13
- exports["default"] = _default;
package/samples/simple.js DELETED
@@ -1,27 +0,0 @@
1
- import createAutoResetEvent from '../src/createAutoResetEvent';
2
- import delay from 'delay';
3
-
4
- export default async function () {
5
- const acquire = createAutoResetEvent();
6
-
7
- await Promise.all([
8
- (async () => {
9
- const release = await acquire();
10
-
11
- console.log('You will see this first.');
12
- await delay(1000);
13
-
14
- release();
15
- })(),
16
- (async () => {
17
- const release = await acquire();
18
-
19
- console.log('You will see this after a second.');
20
- await delay(1000);
21
-
22
- release();
23
- })(),
24
- ]);
25
-
26
- console.log('You will see this last, after two seconds.');
27
- }
@@ -1,5 +0,0 @@
1
- import main from './simple';
2
-
3
- test('sample run correctly', async () => {
4
- await main();
5
- });
@@ -1,22 +0,0 @@
1
- import createDeferred from 'p-defer-es5';
2
-
3
- export default () => {
4
- const queue = [];
5
- const release = () => {
6
- queue.shift();
7
-
8
- queue[0] && queue[0].resolve(release);
9
- };
10
-
11
- return () => {
12
- const deferred = createDeferred();
13
-
14
- queue.push(deferred);
15
-
16
- if (queue[0] === deferred) {
17
- deferred.resolve(release);
18
- }
19
-
20
- return deferred.promise;
21
- };
22
- }
@@ -1,20 +0,0 @@
1
- import 'regenerator-runtime/runtime';
2
- import hasResolved from 'has-resolved';
3
-
4
- import createAutoResetEvent from './createAutoResetEvent';
5
-
6
- test('should acquire one at a time', async () => {
7
- const acquire = createAutoResetEvent();
8
-
9
- const p1 = acquire();
10
- const p2 = acquire();
11
-
12
- expect(await hasResolved(p1)).toBe(true);
13
- expect(await hasResolved(p2)).toBe(false);
14
-
15
- (await p1)();
16
-
17
- expect(await hasResolved(p2)).toBe(true);
18
-
19
- (await p2)();
20
- });
package/src/index.js DELETED
@@ -1,3 +0,0 @@
1
- import createAutoResetEvent from './createAutoResetEvent';
2
-
3
- export default createAutoResetEvent