Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F7535970
test_practical_async.cjs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
870 B
Referenced Files
None
Subscribers
None
test_practical_async.cjs
View Options
// Real-world async pattern: sequential operations
async function fetchUser(id) {
console.log(`Fetching user ${id}...`);
return new Promise(resolve => setTimeout(() => {
resolve({ id, name: `User${id}` });
}, 50));
}
async function fetchUserPosts(userId) {
console.log(`Fetching posts for user ${userId}...`);
return new Promise(resolve => setTimeout(() => {
resolve([`Post1 by ${userId}`, `Post2 by ${userId}`]);
}, 30));
}
async function getUserData(id) {
const user = await fetchUser(id);
console.log("Got user:", user.name);
const posts = await fetchUserPosts(user.id);
console.log("Got posts:", posts.length);
return { user, posts };
}
// This is the common pattern - sequential async calls within one function
getUserData(123).then(data => {
console.log("Complete!", data.user.name, "has", data.posts.length, "posts");
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jun 17, 12:12 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
523846
Default Alt Text
test_practical_async.cjs (870 B)
Attached To
Mode
rANT Ant
Attached
Detach File
Event Timeline
Log In to Comment