@xstd/async-function 1.3.0 → 1.3.1
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/CONTRIBUTING.md +30 -31
- package/README.md +4 -4
- package/package.json +2 -2
- package/src/async-function.d.ts +5 -5
- package/src/async-function.js +5 -5
- package/src/async-function.js.map +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/index.js.map +1 -1
- package/src/types/async-function-like.d.ts +6 -0
- package/src/types/methods/share-concurrent-calls/share-concurrent-calls-options.d.ts +22 -0
- package/src/types/methods/share-concurrent-calls/share-concurrent-calls-options.js +2 -0
- package/src/types/methods/share-concurrent-calls/share-concurrent-calls-options.js.map +1 -0
- package/src/types/methods/then/async-function.then.on-fulfilled-function.d.ts +10 -0
- package/src/types/methods/then/async-function.then.on-rejected-function.d.ts +9 -0
- package/src/types/methods/then/default.async-function.then.on-fulfilled-function.private.d.ts +3 -0
- package/src/types/methods/then/default.async-function.then.on-fulfilled-function.private.js +3 -0
- package/src/types/methods/then/default.async-function.then.on-fulfilled-function.private.js.map +1 -1
- package/src/types/methods/then/default.async-function.then.on-rejected-function.private.d.ts +3 -0
- package/src/types/methods/then/default.async-function.then.on-rejected-function.private.js +3 -0
- package/src/types/methods/then/default.async-function.then.on-rejected-function.private.js.map +1 -1
- package/src/types/methods/transform/transform-async-function-function.d.ts +9 -0
- package/src/types/static-methods/from-send-and-receive/async-function-from-send-and-receive-options.d.ts +12 -0
- package/src/types/methods/share-concurent-calls/share-concurent-calls-options.d.ts +0 -6
- package/src/types/methods/share-concurent-calls/share-concurent-calls-options.js +0 -2
- package/src/types/methods/share-concurent-calls/share-concurent-calls-options.js.map +0 -1
package/CONTRIBUTING.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Contributing
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This project is open to everyone. Feel free to test the library, share it, improve it, and create pull requests.
|
|
4
4
|
|
|
5
5
|
## Getting started
|
|
6
6
|
|
|
@@ -38,40 +38,34 @@ yarn install
|
|
|
38
38
|
### Code
|
|
39
39
|
|
|
40
40
|
- The source code is located in the `src` directory.
|
|
41
|
-
- The
|
|
41
|
+
- The project uses [prettier](https://prettier.io/) to format the code. You'll want to enable and configure it in your IDE.
|
|
42
42
|
- The tests run with [vitest](https://vitest.dev)
|
|
43
43
|
|
|
44
44
|
### Commands
|
|
45
45
|
|
|
46
46
|
- `fb:build`: builds the library.
|
|
47
|
-
- converts the
|
|
47
|
+
- converts the TypeScript files into JavaScript files, copies the SCSS files, and assembles all the assets to create a package ready to be published.
|
|
48
48
|
- some files are handled differently:
|
|
49
|
-
- `*.protected.{ts,scss}` or `**/*.protected/**`: these files are exported under `package-name/protected
|
|
50
|
-
- this is
|
|
49
|
+
- `*.protected.{ts,scss}` or `**/*.protected/**`: these files are exported under `package-name/protected`.
|
|
50
|
+
- this is intended to expose parts of the code that should be restricted to advanced users only, or shared with other libraries requiring _internal_ control.
|
|
51
51
|
- `*.private.{ts,scss}` or `/*.private/**`: these files are **not** exported.
|
|
52
|
-
- this is
|
|
52
|
+
- this is intended to consume parts of the code internally, without exposing them publicly.
|
|
53
53
|
- `fb:format`: formats the code using `prettier`.
|
|
54
|
-
- `fb:test`: runs the tests using `vitest`.
|
|
55
|
-
- `fb:test:coverage`: runs the tests with coverage.
|
|
56
|
-
- by default, 100% code coverage is required, to enforce good quality.
|
|
57
|
-
- `fb:bench`: runs the bench tests.
|
|
58
|
-
- `fb:typedoc`: generates the documentation.
|
|
59
|
-
- if the library exposes publicly only a few and/or simple parts, the documentation may be defined in the `README.md` instead.
|
|
60
54
|
|
|
61
55
|
### To create a PR
|
|
62
56
|
|
|
63
|
-
1.
|
|
64
|
-
1.
|
|
65
|
-
1.
|
|
66
|
-
1.
|
|
67
|
-
1.
|
|
68
|
-
1.
|
|
57
|
+
1. Fork the repository
|
|
58
|
+
1. Add the feature or fix by modifying the code in the `src/` directory
|
|
59
|
+
1. Add/write some tests with good code coverage (run them with `yarn fb:test:coverage`)
|
|
60
|
+
1. Format the code using the command `yarn fb:format`
|
|
61
|
+
1. Commit and push your work following the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) convention
|
|
62
|
+
1. Create a PR from your fork to the upstream repository, clearly explaining what was added or fixed.
|
|
69
63
|
|
|
70
64
|
## Release Workflow
|
|
71
65
|
|
|
72
|
-
> The `release.yml` workflow runs on `pull_request` and `push` events
|
|
73
|
-
> It invokes
|
|
74
|
-
> Note that the `publish` step runs only if the equivalent stable version (`x.y.z`) does not already exist on npm
|
|
66
|
+
> The `release.yml` workflow runs on `pull_request` and `push` events for the `main` and `develop` branches.
|
|
67
|
+
> It invokes `yarn fb:ci:release`, which builds and publishes the packages.
|
|
68
|
+
> Note that the `publish` step runs only if the equivalent stable version (`x.y.z`) does not already exist on npm.
|
|
75
69
|
|
|
76
70
|
### 1. Pull Request to `main` or `develop`
|
|
77
71
|
|
|
@@ -81,6 +75,10 @@ yarn install
|
|
|
81
75
|
|
|
82
76
|
> Use the `dev` versions only if required.
|
|
83
77
|
|
|
78
|
+
> [!NOTE]
|
|
79
|
+
> The PR is published only if it carries the `dev` label — add it to the PR to get a `dev` release; otherwise the release is skipped.
|
|
80
|
+
> Pull requests coming from forks always run in dry-run mode: nothing is published.
|
|
81
|
+
|
|
84
82
|
### 2. Push to `develop`
|
|
85
83
|
|
|
86
84
|
- Impacted packages are published as: `x.y.z-rc.<timestamp>`
|
|
@@ -96,14 +94,14 @@ yarn install
|
|
|
96
94
|
```mermaid
|
|
97
95
|
flowchart LR
|
|
98
96
|
EVENT("WORKFLOW TRIGGER")
|
|
99
|
-
HAS_DEV_TAG{"has &
|
|
97
|
+
HAS_DEV_TAG{"has "dev" label?"}
|
|
100
98
|
SKIP_BUILD(["skip build"])
|
|
101
|
-
BUILD_DEV_PACKAGES["build &
|
|
102
|
-
PUBLISH_DEV_PACKAGES["publish &
|
|
103
|
-
BUILD_RC_PACKAGES["build &
|
|
104
|
-
PUBLISH_RC_PACKAGES["publish &
|
|
105
|
-
BUILD_PROD_PACKAGES["build &
|
|
106
|
-
PUBLISH_PROD_PACKAGES["publish &
|
|
99
|
+
BUILD_DEV_PACKAGES["build "dev" packages"]
|
|
100
|
+
PUBLISH_DEV_PACKAGES["publish "dev" packages"]
|
|
101
|
+
BUILD_RC_PACKAGES["build "rc" packages"]
|
|
102
|
+
PUBLISH_RC_PACKAGES["publish "rc" packages"]
|
|
103
|
+
BUILD_PROD_PACKAGES["build "prod" packages"]
|
|
104
|
+
PUBLISH_PROD_PACKAGES["publish "prod" packages"]
|
|
107
105
|
TARGET_BRANCH{"branch"}
|
|
108
106
|
|
|
109
107
|
EVENT -- "pull_request" --> HAS_DEV_TAG
|
|
@@ -122,6 +120,7 @@ flowchart LR
|
|
|
122
120
|
|
|
123
121
|
## Important Rules
|
|
124
122
|
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
- `-dev` / `-rc` suffixes are generated in CI
|
|
123
|
+
- If an equivalent **stable** version already exists on npm, the release fails — bump the `package.json#version` before releasing (this also blocks `dev` / `rc` releases of a stable version that was already published).
|
|
124
|
+
- The `package.json` version in the repo must always be a stable version (`x.y.z`).
|
|
125
|
+
- The `-dev` / `-rc` suffixes are generated in CI.
|
|
126
|
+
- The npm publish authenticates with [GitHub Actions OIDC](https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-oidc): no `NPM_TOKEN` secret is required (the `release.yml` workflow requests the `id-token: write` permission).
|
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ const fetchUser = fetchJson
|
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
// deduplicate concurrent calls for the same key:
|
|
45
|
-
const getUser = fetchUser.
|
|
45
|
+
const getUser = fetchUser.shareConcurrentCalls({ keyGenerator: ([id]) => id as string });
|
|
46
46
|
|
|
47
47
|
const controller = new AbortController();
|
|
48
48
|
const user = await getUser.call(controller.signal, '42');
|
|
@@ -253,10 +253,10 @@ const safe = fnc.catch((error) => null);
|
|
|
253
253
|
const result = await safe.call(signal); // Response, or null if the request failed
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
##### `
|
|
256
|
+
##### `shareConcurrentCalls` (experimental)
|
|
257
257
|
|
|
258
258
|
```ts
|
|
259
|
-
|
|
259
|
+
shareConcurrentCalls(options: ShareConcurrentCallsOptions<GArguments>): AsyncFunction<GArguments, GReturn>
|
|
260
260
|
```
|
|
261
261
|
|
|
262
262
|
Returns a new async function that deduplicates concurrent calls sharing the same key: while a call is in-flight, subsequent calls with the same key await the same underlying promise instead of triggering a new call.
|
|
@@ -270,7 +270,7 @@ The first call starts the underlying call with its own `AbortController`. Each c
|
|
|
270
270
|
```ts
|
|
271
271
|
const loadUser = new AsyncFunction(async (signal, id: string) =>
|
|
272
272
|
fetchUser(id, { signal }),
|
|
273
|
-
).
|
|
273
|
+
).shareConcurrentCalls({ keyGenerator: ([id]) => id });
|
|
274
274
|
|
|
275
275
|
// 'fetchUser' is called once, both calls await the same result:
|
|
276
276
|
const [a, b] = await Promise.all([loadUser.call(signal, 'a'), loadUser.call(signal, 'a')]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xstd/async-function",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal API around async functions",
|
|
6
6
|
"keywords": [],
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@xstd/abortable": "^1.2.3",
|
|
23
|
-
"@xstd/map-function": "^1.
|
|
23
|
+
"@xstd/map-function": "^1.3.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/src/async-function.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MapFunctionArguments } from '@xstd/map-function';
|
|
2
2
|
import { type AsyncFunctionLike } from './types/async-function-like.ts';
|
|
3
|
-
import { type
|
|
3
|
+
import { type ShareConcurrentCallsOptions } from './types/methods/share-concurrent-calls/share-concurrent-calls-options.ts';
|
|
4
4
|
import { type AsyncFunctionThenOnFulfilledFunction } from './types/methods/then/async-function.then.on-fulfilled-function.ts';
|
|
5
5
|
import { type AsyncFunctionThenOnRejectedFunction } from './types/methods/then/async-function.then.on-rejected-function.ts';
|
|
6
6
|
import { type TransformAsyncFunctionFunction } from './types/methods/transform/transform-async-function-function.ts';
|
|
@@ -137,18 +137,18 @@ export declare class AsyncFunction<GArguments extends readonly unknown[], GRetur
|
|
|
137
137
|
* The first call starts the underlying call with its own `AbortController`. Each caller may abort its own wait without affecting the shared call. When the last consumer settles, the shared controller is aborted, the entry is removed, and a subsequent call starts a new one.
|
|
138
138
|
*
|
|
139
139
|
* @experimental
|
|
140
|
-
* @param {
|
|
141
|
-
* @param {
|
|
140
|
+
* @param {ShareConcurrentCallsOptions<GArguments>} options Configuration object.
|
|
141
|
+
* @param {ShareConcurrentCallsKeyGenerator<GArguments>} options.keyGenerator A function that generates a cache key from the call's arguments. Calls producing the same key share their result.
|
|
142
142
|
* @returns {AsyncFunction<GArguments, GReturn>} A new async function sharing concurrent calls with identical keys.
|
|
143
143
|
*
|
|
144
144
|
* @example
|
|
145
145
|
* ```ts
|
|
146
146
|
* const loadUser = new AsyncFunction(async (signal, id: string) => fetchUser(id, { signal }))
|
|
147
|
-
* .
|
|
147
|
+
* .shareConcurrentCalls({ keyGenerator: ([id]) => id });
|
|
148
148
|
*
|
|
149
149
|
* // 'fetchUser' is called once, both calls await the same result:
|
|
150
150
|
* const [a, b] = await Promise.all([loadUser.call(signal, 'a'), loadUser.call(signal, 'a')]);
|
|
151
151
|
* ```
|
|
152
152
|
*/
|
|
153
|
-
|
|
153
|
+
shareConcurrentCalls({ keyGenerator, }: ShareConcurrentCallsOptions<GArguments>): AsyncFunction<GArguments, GReturn>;
|
|
154
154
|
}
|
package/src/async-function.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { abortify } from '@xstd/abortable';
|
|
2
2
|
import {} from './types/async-function-like.js';
|
|
3
3
|
import {} from './types/call-async-function.js';
|
|
4
|
-
import {} from './types/methods/share-
|
|
4
|
+
import {} from './types/methods/share-concurrent-calls/share-concurrent-calls-options.js';
|
|
5
5
|
import {} from './types/methods/then/async-function.then.on-fulfilled-function.js';
|
|
6
6
|
import {} from './types/methods/then/async-function.then.on-rejected-function.js';
|
|
7
7
|
import { DEFAULT_ASYNC_FUNCTION_THEN_ON_FULFILLED_FUNCTION } from './types/methods/then/default.async-function.then.on-fulfilled-function.private.js';
|
|
@@ -183,20 +183,20 @@ export class AsyncFunction {
|
|
|
183
183
|
* The first call starts the underlying call with its own `AbortController`. Each caller may abort its own wait without affecting the shared call. When the last consumer settles, the shared controller is aborted, the entry is removed, and a subsequent call starts a new one.
|
|
184
184
|
*
|
|
185
185
|
* @experimental
|
|
186
|
-
* @param {
|
|
187
|
-
* @param {
|
|
186
|
+
* @param {ShareConcurrentCallsOptions<GArguments>} options Configuration object.
|
|
187
|
+
* @param {ShareConcurrentCallsKeyGenerator<GArguments>} options.keyGenerator A function that generates a cache key from the call's arguments. Calls producing the same key share their result.
|
|
188
188
|
* @returns {AsyncFunction<GArguments, GReturn>} A new async function sharing concurrent calls with identical keys.
|
|
189
189
|
*
|
|
190
190
|
* @example
|
|
191
191
|
* ```ts
|
|
192
192
|
* const loadUser = new AsyncFunction(async (signal, id: string) => fetchUser(id, { signal }))
|
|
193
|
-
* .
|
|
193
|
+
* .shareConcurrentCalls({ keyGenerator: ([id]) => id });
|
|
194
194
|
*
|
|
195
195
|
* // 'fetchUser' is called once, both calls await the same result:
|
|
196
196
|
* const [a, b] = await Promise.all([loadUser.call(signal, 'a'), loadUser.call(signal, 'a')]);
|
|
197
197
|
* ```
|
|
198
198
|
*/
|
|
199
|
-
|
|
199
|
+
shareConcurrentCalls({ keyGenerator, }) {
|
|
200
200
|
const map = new Map();
|
|
201
201
|
return new AsyncFunction(async (signal, ...args) => {
|
|
202
202
|
signal.throwIfAborted();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-function.js","sourceRoot":"","sources":["../../src/async-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAA0B,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAA0B,MAAM,gCAAgC,CAAC;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"async-function.js","sourceRoot":"","sources":["../../src/async-function.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAA0B,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAA0B,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAoC,MAAM,0EAA0E,CAAC;AAC5H,OAAO,EAA6C,MAAM,mEAAmE,CAAC;AAC9H,OAAO,EAA4C,MAAM,kEAAkE,CAAC;AAC5H,OAAO,EAAE,iDAAiD,EAAE,MAAM,mFAAmF,CAAC;AACtJ,OAAO,EAAE,gDAAgD,EAAE,MAAM,kFAAkF,CAAC;AACpJ,OAAO,EAAuC,MAAM,gEAAgE,CAAC;AACrH,OAAO,EAA+C,MAAM,8FAA8F,CAAC;AAE3J;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,EAAE,CACP,KAA6C;QAE7C,OAAO,KAAK,YAAY,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,aAAa,CAAsB,KAAK,CAAC,CAAC;IAChG,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,kBAAkB,CAAiD,EACxE,IAAI,EACJ,OAAO,GACqD;QAI5D,IAAI,GAAG,aAAa,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAC9B,OAAO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;gBAC1D,KAAK,GAAG;oBACN,UAAU;oBACV,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;oBAC9C,SAAS,EAAE,CAAC;iBACb,CAAC;gBACF,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,KAAK,CAAC,SAAS,EAAE,CAAC;YACpB,CAAC;YAED,IAAI,CAAC;gBACH,OAAO,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;YACnD,CAAC;oBAAS,CAAC;gBACT,KAAK,CAAC,SAAS,EAAE,CAAC;gBAElB,IAAI,KAAK,CAAC,SAAS,KAAK,CAAC,EAAE,CAAC;oBAC1B,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;oBACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;gBAClB,CAAC;YACH,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF"}
|
package/src/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export * from './types/static-methods/from-send-and-receive/async-function-from-
|
|
|
5
5
|
export * from './types/methods/transform/transform-async-function-function.ts';
|
|
6
6
|
export * from './types/methods/then/async-function.then.on-fulfilled-function.ts';
|
|
7
7
|
export * from './types/methods/then/async-function.then.on-rejected-function.ts';
|
|
8
|
-
export * from './types/methods/share-
|
|
8
|
+
export * from './types/methods/share-concurrent-calls/share-concurrent-calls-options.ts';
|
package/src/index.js
CHANGED
|
@@ -5,5 +5,5 @@ export * from './types/static-methods/from-send-and-receive/async-function-from-
|
|
|
5
5
|
export * from './types/methods/transform/transform-async-function-function.js';
|
|
6
6
|
export * from './types/methods/then/async-function.then.on-fulfilled-function.js';
|
|
7
7
|
export * from './types/methods/then/async-function.then.on-rejected-function.js';
|
|
8
|
-
export * from './types/methods/share-
|
|
8
|
+
export * from './types/methods/share-concurrent-calls/share-concurrent-calls-options.js';
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8FAA8F,CAAC;AAC7G,cAAc,gEAAgE,CAAC;AAC/E,cAAc,mEAAmE,CAAC;AAClF,cAAc,kEAAkE,CAAC;AACjF,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8FAA8F,CAAC;AAC7G,cAAc,gEAAgE,CAAC;AAC/E,cAAc,mEAAmE,CAAC;AAClF,cAAc,kEAAkE,CAAC;AACjF,cAAc,0EAA0E,CAAC"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { type AsyncFunction } from '../async-function.ts';
|
|
2
2
|
import { type CallAsyncFunction } from './call-async-function.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Represents anything that can be wrapped into an `AsyncFunction`: either an existing `AsyncFunction` instance, or a plain call function.
|
|
5
|
+
*
|
|
6
|
+
* @template GArguments The tuple type representing the arguments to be provided to the function.
|
|
7
|
+
* @template GReturn The type of the value returned by the async function.
|
|
8
|
+
*/
|
|
3
9
|
export type AsyncFunctionLike<GArguments extends readonly unknown[], GReturn> = AsyncFunction<GArguments, GReturn> | CallAsyncFunction<GArguments, GReturn>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the `AsyncFunction.shareConcurrentCalls` method.
|
|
3
|
+
*
|
|
4
|
+
* @template GArguments The tuple type representing the arguments to be provided to the function.
|
|
5
|
+
*/
|
|
6
|
+
export interface ShareConcurrentCallsOptions<GArguments extends readonly unknown[]> {
|
|
7
|
+
/**
|
|
8
|
+
* Generates a cache key from the call's arguments. Concurrent calls producing the same key share their result.
|
|
9
|
+
*/
|
|
10
|
+
readonly keyGenerator: ShareConcurrentCallsKeyGenerator<GArguments>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generates a cache key from the call's arguments.
|
|
14
|
+
*
|
|
15
|
+
* @template GArguments The tuple type representing the arguments to be provided to the function.
|
|
16
|
+
*
|
|
17
|
+
* @param {...GArguments} args The arguments to be provided to the function.
|
|
18
|
+
* @returns {string} The key identifying concurrent calls to share.
|
|
19
|
+
*/
|
|
20
|
+
export interface ShareConcurrentCallsKeyGenerator<GArguments extends readonly unknown[]> {
|
|
21
|
+
(args: GArguments): string;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"share-concurrent-calls-options.js","sourceRoot":"","sources":["../../../../../src/types/methods/share-concurrent-calls/share-concurrent-calls-options.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the resolved value of an async function call, like the first parameter of `Promise.then`.
|
|
3
|
+
*
|
|
4
|
+
* @template GReturn The type of the value resolved by the async function.
|
|
5
|
+
* @template GNewReturn The type of the value returned by the handler.
|
|
6
|
+
*
|
|
7
|
+
* @param {GReturn} value The value resolved by the async function.
|
|
8
|
+
* @param {AbortSignal} signal The `AbortSignal` received by the call, forwarded to the handler.
|
|
9
|
+
* @returns {PromiseLike<GNewReturn> | GNewReturn} The new value, or a promise of it.
|
|
10
|
+
*/
|
|
1
11
|
export interface AsyncFunctionThenOnFulfilledFunction<GReturn, GNewReturn> {
|
|
2
12
|
(value: GReturn, signal: AbortSignal): PromiseLike<GNewReturn> | GNewReturn;
|
|
3
13
|
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the error thrown by an async function call, like the second parameter of `Promise.then`.
|
|
3
|
+
*
|
|
4
|
+
* @template GNewReturn The type of the value returned by the handler.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} error The error thrown by the async function.
|
|
7
|
+
* @param {AbortSignal} signal The `AbortSignal` received by the call, forwarded to the handler.
|
|
8
|
+
* @returns {PromiseLike<GNewReturn> | GNewReturn} A fallback value, or a promise of it.
|
|
9
|
+
*/
|
|
1
10
|
export interface AsyncFunctionThenOnRejectedFunction<GNewReturn> {
|
|
2
11
|
(error: unknown, signal: AbortSignal): PromiseLike<GNewReturn> | GNewReturn;
|
|
3
12
|
}
|
package/src/types/methods/then/default.async-function.then.on-fulfilled-function.private.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type AsyncFunctionThenOnFulfilledFunction } from './async-function.then.on-fulfilled-function.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Default fulfilment handler: passes the resolved value through unchanged.
|
|
4
|
+
*/
|
|
2
5
|
export declare const DEFAULT_ASYNC_FUNCTION_THEN_ON_FULFILLED_FUNCTION: AsyncFunctionThenOnFulfilledFunction<any, any>;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import {} from './async-function.then.on-fulfilled-function.js';
|
|
2
|
+
/**
|
|
3
|
+
* Default fulfilment handler: passes the resolved value through unchanged.
|
|
4
|
+
*/
|
|
2
5
|
export const DEFAULT_ASYNC_FUNCTION_THEN_ON_FULFILLED_FUNCTION = (value) => value;
|
|
3
6
|
//# sourceMappingURL=default.async-function.then.on-fulfilled-function.private.js.map
|
package/src/types/methods/then/default.async-function.then.on-fulfilled-function.private.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.async-function.then.on-fulfilled-function.private.js","sourceRoot":"","sources":["../../../../../src/types/methods/then/default.async-function.then.on-fulfilled-function.private.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,MAAM,gDAAgD,CAAC;AAE3G,MAAM,CAAC,MAAM,iDAAiD,
|
|
1
|
+
{"version":3,"file":"default.async-function.then.on-fulfilled-function.private.js","sourceRoot":"","sources":["../../../../../src/types/methods/then/default.async-function.then.on-fulfilled-function.private.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6C,MAAM,gDAAgD,CAAC;AAE3G;;GAEG;AACH,MAAM,CAAC,MAAM,iDAAiD,GAG1D,CAAC,KAAU,EAAO,EAAE,CAAC,KAAK,CAAC"}
|
package/src/types/methods/then/default.async-function.then.on-rejected-function.private.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { type AsyncFunctionThenOnRejectedFunction } from './async-function.then.on-rejected-function.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Default rejection handler: re-throws the received error.
|
|
4
|
+
*/
|
|
2
5
|
export declare const DEFAULT_ASYNC_FUNCTION_THEN_ON_REJECTED_FUNCTION: AsyncFunctionThenOnRejectedFunction<any>;
|
package/src/types/methods/then/default.async-function.then.on-rejected-function.private.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.async-function.then.on-rejected-function.private.js","sourceRoot":"","sources":["../../../../../src/types/methods/then/default.async-function.then.on-rejected-function.private.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,MAAM,+CAA+C,CAAC;AAEzG,MAAM,CAAC,MAAM,gDAAgD,
|
|
1
|
+
{"version":3,"file":"default.async-function.then.on-rejected-function.private.js","sourceRoot":"","sources":["../../../../../src/types/methods/then/default.async-function.then.on-rejected-function.private.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,MAAM,+CAA+C,CAAC;AAEzG;;GAEG;AACH,MAAM,CAAC,MAAM,gDAAgD,GAEzD,CAAC,KAAU,EAAO,EAAE;IACtB,MAAM,KAAK,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import { type AsyncFunction } from '../../../async-function.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Transforms an `AsyncFunction` instance into another value.
|
|
4
|
+
*
|
|
5
|
+
* @template GSelf The type of the `AsyncFunction` instance to transform.
|
|
6
|
+
* @template GReturn The type of the value returned by the transformation.
|
|
7
|
+
*
|
|
8
|
+
* @param {GSelf} self The `AsyncFunction` instance to transform.
|
|
9
|
+
* @returns {GReturn} The result of the transformation.
|
|
10
|
+
*/
|
|
2
11
|
export interface TransformAsyncFunctionFunction<GSelf extends AsyncFunction<any, any>, GReturn> {
|
|
3
12
|
(self: GSelf): GReturn;
|
|
4
13
|
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { type AsyncFunctionLike } from '../../async-function-like.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the `AsyncFunction.fromSendAndReceive` static method.
|
|
4
|
+
*
|
|
5
|
+
* @template GArguments The tuple type representing the arguments to be provided to the send and receive functions.
|
|
6
|
+
* @template GReturn The type of the value returned by the receive function.
|
|
7
|
+
*/
|
|
2
8
|
export interface AsyncFunctionFromSendAndReceiveOptions<GArguments extends readonly unknown[], GReturn> {
|
|
9
|
+
/**
|
|
10
|
+
* The "push" async function to trigger (e.g. sending a command or message). Must not return a value.
|
|
11
|
+
*/
|
|
3
12
|
readonly send: AsyncFunctionLike<GArguments, void>;
|
|
13
|
+
/**
|
|
14
|
+
* The "pull" async function to await (e.g. listening for a response or event). Returns the result.
|
|
15
|
+
*/
|
|
4
16
|
readonly receive: AsyncFunctionLike<GArguments, GReturn>;
|
|
5
17
|
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export interface ShareConcurentCallsOptions<GArguments extends readonly unknown[]> {
|
|
2
|
-
readonly keyGenerator: ShareConcurentCallsKeyGenerator<GArguments>;
|
|
3
|
-
}
|
|
4
|
-
export interface ShareConcurentCallsKeyGenerator<GArguments extends readonly unknown[]> {
|
|
5
|
-
(args: GArguments): string;
|
|
6
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"share-concurent-calls-options.js","sourceRoot":"","sources":["../../../../../src/types/methods/share-concurent-calls/share-concurent-calls-options.ts"],"names":[],"mappings":""}
|