7
7
generateRandomKey ,
8
8
} from "./utils" ;
9
9
10
- const COUNT = 5 ;
10
+ const COUNT = 50 ;
11
+ const PARALLEL = true ;
11
12
12
13
async function main ( ) {
13
14
try {
@@ -21,28 +22,47 @@ async function main() {
21
22
const sharedKey = generateRandomKey ( ) ;
22
23
console . log ( `Using shared key: ${ sharedKey } ` ) ;
23
24
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
25
26
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...` ,
27
28
) ;
28
29
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
+ ) ;
36
57
completedCount ++ ;
37
58
console . log (
38
59
`Call ${ index + 1 } /${ COUNT } completed ${ JSON . stringify ( response ) } (${ completedCount } total)` ,
39
60
) ;
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` ) ;
46
66
47
67
// Extract all actor IDs and verify they're all the same
48
68
const actorIds = results . map ( ( result ) => result . response . actor_id ) ;
0 commit comments