ソースを参照

Fix/CI: float promise error handling / log wrap

SukkaW 1 年間 前
コミット
10bde9f1e8
2 ファイル変更16 行追加2 行削除
  1. 15 1
      Build/lib/memo-promise.ts
  2. 1 1
      Build/trace/index.ts

+ 15 - 1
Build/lib/memo-promise.ts

@@ -1,7 +1,21 @@
+const notError = Symbol('notError');
+
 export const createMemoizedPromise = <T>(fn: () => Promise<T>, preload = true): () => Promise<T> => {
 export const createMemoizedPromise = <T>(fn: () => Promise<T>, preload = true): () => Promise<T> => {
-  let promise: Promise<T> | null = preload ? fn() : null;
+  let error: Error | typeof notError = notError;
+
+  let promise: Promise<T> | null = preload
+    ? fn().catch(e => {
+      // Here we record the error so that we can throw it later when the function is called
+      error = e;
+      // Here we make sure the Promise still returns the never type
+      throw e;
+    })
+    : null;
 
 
   return () => {
   return () => {
+    if (error !== notError) {
+      return Promise.reject(error);
+    }
     promise ??= fn();
     promise ??= fn();
     return promise;
     return promise;
   };
   };

+ 1 - 1
Build/trace/index.ts

@@ -181,7 +181,7 @@ function printStats(stats: TraceResult[]): void {
   const realStart = Math.min(...stats.map(i => i.start));
   const realStart = Math.min(...stats.map(i => i.start));
   const realEnd = Math.max(...stats.map(i => i.end));
   const realEnd = Math.max(...stats.map(i => i.end));
 
 
-  const statsStep = ((realEnd - realStart) / 160) | 0;
+  const statsStep = ((realEnd - realStart) / 120) | 0;
 
 
   stats.forEach(stat => {
   stats.forEach(stat => {
     console.log(
     console.log(