@@ -12,16 +12,12 @@ import { usage } from "../usage-api.js";
1212
1313const NOOP_RUNTIME_MANAGER = new NoopRuntimeManager ( ) ;
1414
15- const concurrentWaitErrorMessage =
16- "Parallel waits are not supported, e.g. using Promise.all() around our wait functions." ;
17-
1815/**
1916 * All state must be inside the RuntimeManager, do NOT store it on this class.
2017 * This is because of the "dual package hazard", this can be bundled multiple times.
2118 */
2219export class RuntimeAPI {
2320 private static _instance ?: RuntimeAPI ;
24- private isExecutingWait = false ;
2521
2622 private constructor ( ) { }
2723
@@ -34,31 +30,23 @@ export class RuntimeAPI {
3430 }
3531
3632 public waitForDuration ( ms : number ) : Promise < void > {
37- return this . #preventConcurrentWaits( ( ) =>
38- usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitForDuration ( ms ) )
39- ) ;
33+ return usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitForDuration ( ms ) ) ;
4034 }
4135
4236 public waitUntil ( date : Date ) : Promise < void > {
43- return this . #preventConcurrentWaits( ( ) =>
44- usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitUntil ( date ) )
45- ) ;
37+ return usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitUntil ( date ) ) ;
4638 }
4739
4840 public waitForTask ( params : { id : string ; ctx : TaskRunContext } ) : Promise < TaskRunExecutionResult > {
49- return this . #preventConcurrentWaits( ( ) =>
50- usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitForTask ( params ) )
51- ) ;
41+ return usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitForTask ( params ) ) ;
5242 }
5343
5444 public waitForBatch ( params : {
5545 id : string ;
5646 runs : string [ ] ;
5747 ctx : TaskRunContext ;
5848 } ) : Promise < BatchTaskRunExecutionResult > {
59- return this . #preventConcurrentWaits( ( ) =>
60- usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitForBatch ( params ) )
61- ) ;
49+ return usage . pauseAsync ( ( ) => this . #getRuntimeManager( ) . waitForBatch ( params ) ) ;
6250 }
6351
6452 public setGlobalRuntimeManager ( runtimeManager : RuntimeManager ) : boolean {
@@ -73,19 +61,4 @@ export class RuntimeAPI {
7361 #getRuntimeManager( ) : RuntimeManager {
7462 return getGlobal ( API_NAME ) ?? NOOP_RUNTIME_MANAGER ;
7563 }
76-
77- async #preventConcurrentWaits< T > ( cb : ( ) => Promise < T > ) : Promise < T > {
78- if ( this . isExecutingWait ) {
79- console . error ( concurrentWaitErrorMessage ) ;
80- throw new Error ( concurrentWaitErrorMessage ) ;
81- }
82-
83- this . isExecutingWait = true ;
84-
85- try {
86- return await cb ( ) ;
87- } finally {
88- this . isExecutingWait = false ;
89- }
90- }
9164}
0 commit comments