parallel-workflow.ts
1 /** 2 * Parallel Workflow Example 3 * Demonstrates parallel execution of tasks 4 */ 5 6 import { parallel } from 'praisonai'; 7 8 async function main() { 9 console.log('Starting parallel tasks...\n'); 10 11 const results = await parallel([ 12 async () => { 13 console.log('Task 1: Starting...'); 14 await new Promise(r => setTimeout(r, 1000)); 15 console.log('Task 1: Complete'); 16 return 'Result 1'; 17 }, 18 async () => { 19 console.log('Task 2: Starting...'); 20 await new Promise(r => setTimeout(r, 500)); 21 console.log('Task 2: Complete'); 22 return 'Result 2'; 23 }, 24 async () => { 25 console.log('Task 3: Starting...'); 26 await new Promise(r => setTimeout(r, 750)); 27 console.log('Task 3: Complete'); 28 return 'Result 3'; 29 } 30 ]); 31 32 console.log('\nAll tasks complete!'); 33 console.log('Results:', results); 34 } 35 36 main().catch(console.error);