mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Perf: optimize sort domains & preload promise
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
export const createMemoizedPromise = <T>(fn: () => Promise<T>): () => Promise<T> => {
|
||||
export const createMemoizedPromise = <T>(fn: () => Promise<T>, preload = true): () => Promise<T> => {
|
||||
let promise: Promise<T> | null = null;
|
||||
|
||||
if (preload) {
|
||||
promise = fn();
|
||||
}
|
||||
|
||||
return () => {
|
||||
promise ||= fn();
|
||||
promise ??= fn();
|
||||
return promise;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user