radashi 13.0.1 → 13.0.2

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 CHANGED
@@ -596,7 +596,7 @@ function withResolvers() {
596
596
 
597
597
  // src/async/promiseMemo.ts
598
598
  function promiseMemo(func, options = {}) {
599
- const { key: keyFunc, ttl, cache = {} } = options;
599
+ const { key: keyFunc, ttl, cache = /* @__PURE__ */ Object.create(null) } = options;
600
600
  return function callWithMemo(...args) {
601
601
  const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
602
602
  const existing = cache[key];
@@ -609,12 +609,14 @@ function promiseMemo(func, options = {}) {
609
609
  }
610
610
  }
611
611
  const promise = func(...args);
612
- cache[key] = {
612
+ const entry = cache[key] = {
613
613
  exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
614
614
  value: promise
615
615
  };
616
616
  promise.catch(() => {
617
- delete cache[key];
617
+ if (cache[key] === entry) {
618
+ delete cache[key];
619
+ }
618
620
  });
619
621
  return promise;
620
622
  };
@@ -1538,9 +1540,12 @@ var Semaphore = class {
1538
1540
  if (weight > this.maxCapacity) {
1539
1541
  throw new Error("weight must be \u2264 maxCapacity");
1540
1542
  }
1543
+ if (signal?.aborted) {
1544
+ throw signal.reason;
1545
+ }
1541
1546
  const request = withResolvers();
1542
1547
  const permit = new SemaphorePermit(this, request, weight);
1543
- if (signal) {
1548
+ if (signal && this.capacity < weight) {
1544
1549
  const abort = () => {
1545
1550
  const index = this.queue.indexOf(permit);
1546
1551
  if (index >= 0) {
@@ -1576,11 +1581,12 @@ var Semaphore = class {
1576
1581
  */
1577
1582
  release(permit) {
1578
1583
  this.capacity += permit.weight;
1579
- const nextPermit = this.queue[0];
1580
- if (nextPermit && this.capacity >= nextPermit.weight) {
1584
+ let nextPermit = this.queue[0];
1585
+ while (nextPermit && this.capacity >= nextPermit.weight) {
1581
1586
  this.capacity -= nextPermit.weight;
1582
1587
  this.queue.shift();
1583
1588
  nextPermit.request.resolve();
1589
+ nextPermit = this.queue[0];
1584
1590
  }
1585
1591
  }
1586
1592
  };
@@ -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
@@ -594,7 +594,7 @@ function withResolvers() {
594
594
 
595
595
  // src/async/promiseMemo.ts
596
596
  function promiseMemo(func, options = {}) {
597
- const { key: keyFunc, ttl, cache = {} } = options;
597
+ const { key: keyFunc, ttl, cache = /* @__PURE__ */ Object.create(null) } = options;
598
598
  return function callWithMemo(...args) {
599
599
  const key = keyFunc ? keyFunc(...args) : JSON.stringify({ args });
600
600
  const existing = cache[key];
@@ -607,12 +607,14 @@ function promiseMemo(func, options = {}) {
607
607
  }
608
608
  }
609
609
  const promise = func(...args);
610
- cache[key] = {
610
+ const entry = cache[key] = {
611
611
  exp: ttl ? (/* @__PURE__ */ new Date()).getTime() + ttl : null,
612
612
  value: promise
613
613
  };
614
614
  promise.catch(() => {
615
- delete cache[key];
615
+ if (cache[key] === entry) {
616
+ delete cache[key];
617
+ }
616
618
  });
617
619
  return promise;
618
620
  };
@@ -1536,9 +1538,12 @@ var Semaphore = class {
1536
1538
  if (weight > this.maxCapacity) {
1537
1539
  throw new Error("weight must be \u2264 maxCapacity");
1538
1540
  }
1541
+ if (signal?.aborted) {
1542
+ throw signal.reason;
1543
+ }
1539
1544
  const request = withResolvers();
1540
1545
  const permit = new SemaphorePermit(this, request, weight);
1541
- if (signal) {
1546
+ if (signal && this.capacity < weight) {
1542
1547
  const abort = () => {
1543
1548
  const index = this.queue.indexOf(permit);
1544
1549
  if (index >= 0) {
@@ -1574,11 +1579,12 @@ var Semaphore = class {
1574
1579
  */
1575
1580
  release(permit) {
1576
1581
  this.capacity += permit.weight;
1577
- const nextPermit = this.queue[0];
1578
- if (nextPermit && this.capacity >= nextPermit.weight) {
1582
+ let nextPermit = this.queue[0];
1583
+ while (nextPermit && this.capacity >= nextPermit.weight) {
1579
1584
  this.capacity -= nextPermit.weight;
1580
1585
  this.queue.shift();
1581
1586
  nextPermit.request.resolve();
1587
+ nextPermit = this.queue[0];
1582
1588
  }
1583
1589
  }
1584
1590
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radashi",
3
- "version": "13.0.1",
3
+ "version": "13.0.2",
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": {