radashi 13.0.1 → 13.0.3
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/dist/radashi.cjs +13 -6
- package/dist/radashi.d.cts +1 -0
- package/dist/radashi.d.ts +1 -0
- package/dist/radashi.js +13 -6
- package/package.json +1 -1
package/dist/radashi.cjs
CHANGED
|
@@ -518,6 +518,7 @@ async function retry(options, func) {
|
|
|
518
518
|
const signal = options?.signal;
|
|
519
519
|
let i = 0;
|
|
520
520
|
while (true) {
|
|
521
|
+
signal?.throwIfAborted();
|
|
521
522
|
const [err, result] = await tryit(func)((err2) => {
|
|
522
523
|
throw { _exited: err2 };
|
|
523
524
|
});
|
|
@@ -596,7 +597,7 @@ function withResolvers() {
|
|
|
596
597
|
|
|
597
598
|
// src/async/promiseMemo.ts
|
|
598
599
|
function promiseMemo(func, options = {}) {
|
|
599
|
-
const { key: keyFunc, ttl, cache =
|
|
600
|
+
const { key: keyFunc, ttl, cache = /* @__PURE__ */ Object.create(null) } = options;
|
|
600
601
|
return function callWithMemo(...args) {
|
|
601
602
|
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
602
603
|
const existing = cache[key];
|
|
@@ -609,12 +610,14 @@ function promiseMemo(func, options = {}) {
|
|
|
609
610
|
}
|
|
610
611
|
}
|
|
611
612
|
const promise = func(...args);
|
|
612
|
-
cache[key] = {
|
|
613
|
+
const entry = cache[key] = {
|
|
613
614
|
exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
|
|
614
615
|
value: promise
|
|
615
616
|
};
|
|
616
617
|
promise.catch(() => {
|
|
617
|
-
|
|
618
|
+
if (cache[key] === entry) {
|
|
619
|
+
delete cache[key];
|
|
620
|
+
}
|
|
618
621
|
});
|
|
619
622
|
return promise;
|
|
620
623
|
};
|
|
@@ -1538,9 +1541,12 @@ var Semaphore = class {
|
|
|
1538
1541
|
if (weight > this.maxCapacity) {
|
|
1539
1542
|
throw new Error("weight must be \u2264 maxCapacity");
|
|
1540
1543
|
}
|
|
1544
|
+
if (signal?.aborted) {
|
|
1545
|
+
throw signal.reason;
|
|
1546
|
+
}
|
|
1541
1547
|
const request = withResolvers();
|
|
1542
1548
|
const permit = new SemaphorePermit(this, request, weight);
|
|
1543
|
-
if (signal) {
|
|
1549
|
+
if (signal && this.capacity < weight) {
|
|
1544
1550
|
const abort = () => {
|
|
1545
1551
|
const index = this.queue.indexOf(permit);
|
|
1546
1552
|
if (index >= 0) {
|
|
@@ -1576,11 +1582,12 @@ var Semaphore = class {
|
|
|
1576
1582
|
*/
|
|
1577
1583
|
release(permit) {
|
|
1578
1584
|
this.capacity += permit.weight;
|
|
1579
|
-
|
|
1580
|
-
|
|
1585
|
+
let nextPermit = this.queue[0];
|
|
1586
|
+
while (nextPermit && this.capacity >= nextPermit.weight) {
|
|
1581
1587
|
this.capacity -= nextPermit.weight;
|
|
1582
1588
|
this.queue.shift();
|
|
1583
1589
|
nextPermit.request.resolve();
|
|
1590
|
+
nextPermit = this.queue[0];
|
|
1584
1591
|
}
|
|
1585
1592
|
}
|
|
1586
1593
|
};
|
package/dist/radashi.d.cts
CHANGED
|
@@ -3358,6 +3358,7 @@ declare namespace DurationParser {
|
|
|
3358
3358
|
}
|
|
3359
3359
|
|
|
3360
3360
|
interface AbortSignal {
|
|
3361
|
+
aborted?: boolean;
|
|
3361
3362
|
reason?: unknown;
|
|
3362
3363
|
addEventListener(type: 'abort', listener: () => void): void;
|
|
3363
3364
|
removeEventListener(type: 'abort', listener: () => void): void;
|
package/dist/radashi.d.ts
CHANGED
|
@@ -3358,6 +3358,7 @@ declare namespace DurationParser {
|
|
|
3358
3358
|
}
|
|
3359
3359
|
|
|
3360
3360
|
interface AbortSignal {
|
|
3361
|
+
aborted?: boolean;
|
|
3361
3362
|
reason?: unknown;
|
|
3362
3363
|
addEventListener(type: 'abort', listener: () => void): void;
|
|
3363
3364
|
removeEventListener(type: 'abort', listener: () => void): void;
|
package/dist/radashi.js
CHANGED
|
@@ -516,6 +516,7 @@ async function retry(options, func) {
|
|
|
516
516
|
const signal = options?.signal;
|
|
517
517
|
let i = 0;
|
|
518
518
|
while (true) {
|
|
519
|
+
signal?.throwIfAborted();
|
|
519
520
|
const [err, result] = await tryit(func)((err2) => {
|
|
520
521
|
throw { _exited: err2 };
|
|
521
522
|
});
|
|
@@ -594,7 +595,7 @@ function withResolvers() {
|
|
|
594
595
|
|
|
595
596
|
// src/async/promiseMemo.ts
|
|
596
597
|
function promiseMemo(func, options = {}) {
|
|
597
|
-
const { key: keyFunc, ttl, cache =
|
|
598
|
+
const { key: keyFunc, ttl, cache = /* @__PURE__ */ Object.create(null) } = options;
|
|
598
599
|
return function callWithMemo(...args) {
|
|
599
600
|
const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
|
|
600
601
|
const existing = cache[key];
|
|
@@ -607,12 +608,14 @@ function promiseMemo(func, options = {}) {
|
|
|
607
608
|
}
|
|
608
609
|
}
|
|
609
610
|
const promise = func(...args);
|
|
610
|
-
cache[key] = {
|
|
611
|
+
const entry = cache[key] = {
|
|
611
612
|
exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
|
|
612
613
|
value: promise
|
|
613
614
|
};
|
|
614
615
|
promise.catch(() => {
|
|
615
|
-
|
|
616
|
+
if (cache[key] === entry) {
|
|
617
|
+
delete cache[key];
|
|
618
|
+
}
|
|
616
619
|
});
|
|
617
620
|
return promise;
|
|
618
621
|
};
|
|
@@ -1536,9 +1539,12 @@ var Semaphore = class {
|
|
|
1536
1539
|
if (weight > this.maxCapacity) {
|
|
1537
1540
|
throw new Error("weight must be \u2264 maxCapacity");
|
|
1538
1541
|
}
|
|
1542
|
+
if (signal?.aborted) {
|
|
1543
|
+
throw signal.reason;
|
|
1544
|
+
}
|
|
1539
1545
|
const request = withResolvers();
|
|
1540
1546
|
const permit = new SemaphorePermit(this, request, weight);
|
|
1541
|
-
if (signal) {
|
|
1547
|
+
if (signal && this.capacity < weight) {
|
|
1542
1548
|
const abort = () => {
|
|
1543
1549
|
const index = this.queue.indexOf(permit);
|
|
1544
1550
|
if (index >= 0) {
|
|
@@ -1574,11 +1580,12 @@ var Semaphore = class {
|
|
|
1574
1580
|
*/
|
|
1575
1581
|
release(permit) {
|
|
1576
1582
|
this.capacity += permit.weight;
|
|
1577
|
-
|
|
1578
|
-
|
|
1583
|
+
let nextPermit = this.queue[0];
|
|
1584
|
+
while (nextPermit && this.capacity >= nextPermit.weight) {
|
|
1579
1585
|
this.capacity -= nextPermit.weight;
|
|
1580
1586
|
this.queue.shift();
|
|
1581
1587
|
nextPermit.request.resolve();
|
|
1588
|
+
nextPermit = this.queue[0];
|
|
1582
1589
|
}
|
|
1583
1590
|
}
|
|
1584
1591
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radashi",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
|
|
6
6
|
"repository": {
|