@pistonite/pure 0.26.7 → 0.26.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pistonite/pure",
3
- "version": "0.26.7",
3
+ "version": "0.26.8",
4
4
  "type": "module",
5
5
  "description": "Pure TypeScript libraries for my projects",
6
6
  "homepage": "https://github.com/Pistonite/pure",
package/src/sync/index.ts CHANGED
@@ -14,8 +14,9 @@ export { latest, type LatestConstructor, type UpdateArgsFn } from "./latest.ts";
14
14
  export { debounce, type DebounceConstructor } from "./debounce.ts";
15
15
  export { batch, type BatchConstructor } from "./batch.ts";
16
16
  export { once, type OnceConstructor } from "./once.ts";
17
+ export { makePromise, type PromiseHandle } from "./util.ts";
17
18
 
18
- // types
19
+ // helper types
19
20
  export type { AnyFn, AwaitRet } from "./util.ts";
20
21
 
21
22
  // unstable
package/src/sync/util.ts CHANGED
@@ -1,23 +1,28 @@
1
- export const makePromise = <T>(): {
2
- promise: Promise<T>;
3
- resolve: (value: T | PromiseLike<T>) => void;
4
- reject: (reason?: unknown) => void;
5
- } => {
6
- let resolve;
7
- let reject;
1
+ /**
2
+ * Make a {@link PromiseHandle} with the promise object separate from
3
+ * its resolve and reject methods
4
+ */
5
+ export const makePromise = <T>(): PromiseHandle<T> => {
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ let resolve: any;
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ let reject: any;
8
10
  const promise = new Promise<T>((res, rej) => {
9
11
  resolve = res;
10
12
  reject = rej;
11
13
  });
12
- if (!resolve || !reject) {
13
- throw new Error(
14
- "Promise callbacks not set. This is a bug in the JS engine!",
15
- );
16
- }
17
14
  return { promise, resolve, reject };
18
15
  };
19
16
 
20
- export type PromiseHandle<T> = ReturnType<typeof makePromise<T>>;
17
+ /**
18
+ * A handle of the promise that breaks down the promise object
19
+ * and its resolve and reject functions
20
+ */
21
+ export type PromiseHandle<T> = {
22
+ promise: Promise<T>;
23
+ resolve: (value: T | PromiseLike<T>) => void;
24
+ reject: (reason?: unknown) => void;
25
+ };
21
26
 
22
27
  /** Shorthand for Awaited<ReturnType<T>> */
23
28
  // eslint-disable-next-line @typescript-eslint/no-explicit-any