77 generateRandomKey ,
88} from "./utils" ;
99
10- const COUNT = 5 ;
10+ const COUNT = 50 ;
11+ const PARALLEL = true ;
1112
1213async function main ( ) {
1314 try {
@@ -21,28 +22,47 @@ async function main() {
2122 const sharedKey = generateRandomKey ( ) ;
2223 console . log ( `Using shared key: ${ sharedKey } ` ) ;
2324
24- // Create parallel calls to get or create actor with the same key
25+ // Create calls to get or create actor with the same key
2526 console . log (
26- `Creating ${ COUNT } parallel get-or-create calls with shared key...` ,
27+ `Creating ${ COUNT } ${ PARALLEL ? " parallel" : "serial" } get-or-create calls with shared key...` ,
2728 ) ;
2829 let completedCount = 0 ;
29- const promises = Array . from ( { length : COUNT } , ( _ , index ) =>
30- getOrCreateActorById (
31- namespaceName ,
32- actorName ,
33- sharedKey ,
34- runnerNameSelector ,
35- ) . then ( ( response ) => {
30+
31+ let results ;
32+ if ( PARALLEL ) {
33+ const promises = Array . from ( { length : COUNT } , ( _ , index ) =>
34+ getOrCreateActorById (
35+ namespaceName ,
36+ actorName ,
37+ sharedKey ,
38+ runnerNameSelector ,
39+ ) . then ( ( response ) => {
40+ completedCount ++ ;
41+ console . log (
42+ `Call ${ index + 1 } /${ COUNT } completed ${ JSON . stringify ( response ) } (${ completedCount } total)` ,
43+ ) ;
44+ return { index, response } ;
45+ } ) ,
46+ ) ;
47+ results = await Promise . all ( promises ) ;
48+ } else {
49+ results = [ ] ;
50+ for ( let index = 0 ; index < COUNT ; index ++ ) {
51+ const response = await getOrCreateActorById (
52+ namespaceName ,
53+ actorName ,
54+ sharedKey ,
55+ runnerNameSelector ,
56+ ) ;
3657 completedCount ++ ;
3758 console . log (
3859 `Call ${ index + 1 } /${ COUNT } completed ${ JSON . stringify ( response ) } (${ completedCount } total)` ,
3960 ) ;
40- return { index, response } ;
41- } ) ,
42- ) ;
43-
44- const results = await Promise . all ( promises ) ;
45- console . log ( `✓ Completed all ${ COUNT } parallel calls` ) ;
61+ results . push ( { index, response } ) ;
62+ }
63+ }
64+
65+ console . log ( `✓ Completed all ${ COUNT } ${ PARALLEL ? "parallel" : "serial" } calls` ) ;
4666
4767 // Extract all actor IDs and verify they're all the same
4868 const actorIds = results . map ( ( result ) => result . response . actor_id ) ;
0 commit comments