@fireproof/vendor 0.22.0-keybag → 0.23.1-dev-issue-1057

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.
@@ -1,81 +1,2 @@
1
- export interface LimitFunction {
2
- /**
3
- The number of promises that are currently running.
4
- */
5
- readonly activeCount: number;
6
-
7
- /**
8
- The number of promises that are waiting to run (i.e. their internal `fn` was not called yet).
9
- */
10
- readonly pendingCount: number;
11
-
12
- /**
13
- Get or set the concurrency limit.
14
- */
15
- concurrency: number;
16
-
17
- /**
18
- Discard pending promises that are waiting to run.
19
-
20
- This might be useful if you want to teardown the queue at the end of your program's lifecycle or discard any function calls referencing an intermediary state of your app.
21
-
22
- Note: This does not cancel promises that are already running.
23
- */
24
- clearQueue: () => void;
25
-
26
- /**
27
- @param fn - Promise-returning/async function.
28
- @param arguments - Any arguments to pass through to `fn`. Support for passing arguments on to the `fn` is provided in order to be able to avoid creating unnecessary closures. You probably don't need this optimization unless you're pushing a lot of functions.
29
- @returns The promise returned by calling `fn(...arguments)`.
30
- */
31
- <Arguments extends unknown[], ReturnType>(
32
- function_: (...arguments_: Arguments) => PromiseLike<ReturnType> | ReturnType,
33
- ...arguments_: Arguments
34
- ): Promise<ReturnType>;
35
- }
36
-
37
- /**
38
- Run multiple promise-returning & async functions with limited concurrency.
39
-
40
- @param concurrency - Concurrency limit. Minimum: `1`.
41
- @returns A `limit` function.
42
- */
43
- export default function pLimit(concurrency: number): LimitFunction;
44
-
45
- export interface Options {
46
- /**
47
- Concurrency limit.
48
-
49
- Minimum: `1`.
50
- */
51
- readonly concurrency: number;
52
- }
53
-
54
- /**
55
- Returns a function with limited concurrency.
56
-
57
- The returned function manages its own concurrent executions, allowing you to call it multiple times without exceeding the specified concurrency limit.
58
-
59
- Ideal for scenarios where you need to control the number of simultaneous executions of a single function, rather than managing concurrency across multiple functions.
60
-
61
- @param function_ - Promise-returning/async function.
62
- @return Function with limited concurrency.
63
-
64
- @example
65
- ```
66
- import {limitFunction} from 'p-limit';
67
-
68
- const limitedFunction = limitFunction(async () => {
69
- return doSomething();
70
- }, {concurrency: 1});
71
-
72
- const input = Array.from({length: 10}, limitedFunction);
73
-
74
- // Only one promise is run at once.
75
- await Promise.all(input);
76
- ```
77
- */
78
- export function limitFunction<Arguments extends unknown[], ReturnType>(
79
- function_: (...arguments_: Arguments) => PromiseLike<ReturnType> | ReturnType,
80
- option: Options,
81
- ): (...arguments_: Arguments) => Promise<ReturnType>;
1
+ export default function pLimit(concurrency: any): (function_: any, ...arguments_: any[]) => Promise<unknown>;
2
+ export declare function limitFunction(function_: any, option: any): (...arguments_: any[]) => Promise<unknown>;
package/p-limit/index.js CHANGED
@@ -1,104 +1,78 @@
1
1
  import Queue from "yocto-queue";
2
-
3
2
  export default function pLimit(concurrency) {
4
- validateConcurrency(concurrency);
5
-
6
- const queue = new Queue();
7
- let activeCount = 0;
8
-
9
- const resumeNext = () => {
10
- if (activeCount < concurrency && queue.size > 0) {
11
- queue.dequeue()();
12
- // Since `pendingCount` has been decreased by one, increase `activeCount` by one.
13
- activeCount++;
14
- }
15
- };
16
-
17
- const next = () => {
18
- activeCount--;
19
-
20
- resumeNext();
21
- };
22
-
23
- const run = async (function_, resolve, arguments_) => {
24
- const result = (async () => function_(...arguments_))();
25
-
26
- resolve(result);
27
-
28
- try {
29
- await result;
30
- } catch {
31
- /* */
32
- }
33
-
34
- next();
35
- };
36
-
37
- const enqueue = (function_, resolve, arguments_) => {
38
- // Queue `internalResolve` instead of the `run` function
39
- // to preserve asynchronous context.
40
- new Promise((internalResolve) => {
41
- queue.enqueue(internalResolve);
42
- }).then(run.bind(undefined, function_, resolve, arguments_));
43
-
44
- (async () => {
45
- // This function needs to wait until the next microtask before comparing
46
- // `activeCount` to `concurrency`, because `activeCount` is updated asynchronously
47
- // after the `internalResolve` function is dequeued and called. The comparison in the if-statement
48
- // needs to happen asynchronously as well to get an up-to-date value for `activeCount`.
49
- await Promise.resolve();
50
-
51
- if (activeCount < concurrency) {
3
+ validateConcurrency(concurrency);
4
+ const queue = new Queue();
5
+ let activeCount = 0;
6
+ const resumeNext = () => {
7
+ if (activeCount < concurrency && queue.size > 0) {
8
+ queue.dequeue()();
9
+ activeCount++;
10
+ }
11
+ };
12
+ const next = () => {
13
+ activeCount--;
52
14
  resumeNext();
53
- }
54
- })();
55
- };
56
-
57
- const generator = (function_, ...arguments_) =>
58
- new Promise((resolve) => {
59
- enqueue(function_, resolve, arguments_);
15
+ };
16
+ const run = async (function_, resolve, arguments_) => {
17
+ const result = (async () => function_(...arguments_))();
18
+ resolve(result);
19
+ try {
20
+ await result;
21
+ }
22
+ catch {
23
+ /* */
24
+ }
25
+ next();
26
+ };
27
+ const enqueue = (function_, resolve, arguments_) => {
28
+ new Promise((internalResolve) => {
29
+ queue.enqueue(internalResolve);
30
+ }).then(run.bind(undefined, function_, resolve, arguments_));
31
+ (async () => {
32
+ await Promise.resolve();
33
+ if (activeCount < concurrency) {
34
+ resumeNext();
35
+ }
36
+ })();
37
+ };
38
+ const generator = (function_, ...arguments_) => new Promise((resolve) => {
39
+ enqueue(function_, resolve, arguments_);
60
40
  });
61
-
62
- Object.defineProperties(generator, {
63
- activeCount: {
64
- get: () => activeCount,
65
- },
66
- pendingCount: {
67
- get: () => queue.size,
68
- },
69
- clearQueue: {
70
- value() {
71
- queue.clear();
72
- },
73
- },
74
- concurrency: {
75
- get: () => concurrency,
76
-
77
- set(newConcurrency) {
78
- validateConcurrency(newConcurrency);
79
- concurrency = newConcurrency;
80
-
81
- queueMicrotask(() => {
82
- while (activeCount < concurrency && queue.size > 0) {
83
- resumeNext();
84
- }
85
- });
86
- },
87
- },
88
- });
89
-
90
- return generator;
41
+ Object.defineProperties(generator, {
42
+ activeCount: {
43
+ get: () => activeCount,
44
+ },
45
+ pendingCount: {
46
+ get: () => queue.size,
47
+ },
48
+ clearQueue: {
49
+ value() {
50
+ queue.clear();
51
+ },
52
+ },
53
+ concurrency: {
54
+ get: () => concurrency,
55
+ set(newConcurrency) {
56
+ validateConcurrency(newConcurrency);
57
+ concurrency = newConcurrency;
58
+ queueMicrotask(() => {
59
+ while (activeCount < concurrency && queue.size > 0) {
60
+ resumeNext();
61
+ }
62
+ });
63
+ },
64
+ },
65
+ });
66
+ return generator;
91
67
  }
92
-
93
68
  export function limitFunction(function_, option) {
94
- const { concurrency } = option;
95
- const limit = pLimit(concurrency);
96
-
97
- return (...arguments_) => limit(() => function_(...arguments_));
69
+ const { concurrency } = option;
70
+ const limit = pLimit(concurrency);
71
+ return (...arguments_) => limit(() => function_(...arguments_));
98
72
  }
99
-
100
73
  function validateConcurrency(concurrency) {
101
- if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
102
- throw new TypeError("Expected `concurrency` to be a number from 1 and up");
103
- }
74
+ if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
75
+ throw new TypeError("Expected `concurrency` to be a number from 1 and up");
76
+ }
104
77
  }
78
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../jsr/p-limit/index.js"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,WAAW,EAAE;IAC1C,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAEjC,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC;IAC1B,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC;QACvB,IAAI,WAAW,GAAG,WAAW,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAChD,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;YAElB,WAAW,EAAE,CAAC;QAChB,CAAC;IAAA,CACF,CAAC;IAEF,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC;QACjB,WAAW,EA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
+ const input = [limit(async () => "foo"), limit(async () => "bar"), limit(async () => undefined)];
5
+ expectType(Promise.all(input));
6
+ expectType(limit((a) => "", "test"));
7
+ expectType(limit(async (a, b) => "", "test", 1));
8
+ expectType(limit.activeCount);
9
+ expectType(limit.pendingCount);
10
+ expectType(limit.clearQueue());
11
+ //# sourceMappingURL=index.test-d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.test-d.js","sourceRoot":"","sources":["../../jsr/p-limit/index.test-d.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,MAAM,MAAM,YAAY,CAAC;AAEhC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;AAExB,MAAM,KAAK,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAEjG,UAAU,CAAkC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;AAGhE,UAAU,CAAkB,KAAK,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;AAE9D,UAAU,CAAkB,KAAK,CAAC,KAAK,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;AAElF,UAAU,CAAS,KAAK,CAAC,WAAW,CAAC,CAAC;AACtC,UAAU,CAAS,KAAK,CAAC,YAAY,CAAC,CAAC;AAGvC,UAAU,CAAO,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};