completionId: cgen-ab34dee1a9274bd1b034bdc8fe38c2de

cgen-ab34dee1a9274bd1b034bdc8fe38c2de
This commit is contained in:
Builder.io 2025-11-05 07:05:20 +00:00
parent 9c87fb3341
commit ba8bb1da59

View file

@ -112,11 +112,20 @@ export default function Feed() {
const fetchFeed = useCallback(async () => {
setIsLoading(true);
try {
// Parallelize posts and following fetch
// Add timeout to prevent hanging indefinitely
const withTimeout = <T,>(promise: Promise<T>, ms: number): Promise<T> =>
Promise.race([
promise,
new Promise<T>((_, reject) =>
setTimeout(() => reject(new Error("Request timeout")), ms)
),
]);
// Parallelize posts and following fetch with 10s timeout
const [posts, flw] = await Promise.all([
communityService.getPosts(30),
withTimeout(communityService.getPosts(30), 10000),
user?.id
? aethexSocialService.getFollowing(user.id)
? withTimeout(aethexSocialService.getFollowing(user.id), 10000)
: Promise.resolve([]),
]);