@@ -3,7 +3,6 @@ import * as v8 from 'node:v8';
3
3
import * as fs from 'node:fs' ;
4
4
import * as os from 'node:os' ;
5
5
import { Heap } from 'heap-js' ;
6
- import { Subject , firstValueFrom } from 'rxjs' ;
7
6
import * as native from '@temporalio/core-bridge' ;
8
7
import {
9
8
pollLogs ,
@@ -134,7 +133,8 @@ export class Runtime {
134
133
protected pendingCreations = 0 ;
135
134
/** Track the registered native objects to automatically shutdown when all have been deregistered */
136
135
protected readonly backRefs = new Set < TrackedNativeObject > ( ) ;
137
- protected readonly stopPollingForLogs = new Subject < void > ( ) ;
136
+ protected stopPollingForLogs = false ;
137
+ protected stopPollingForLogsCallback ?: ( ) => void ;
138
138
protected readonly logPollPromise : Promise < void > ;
139
139
public readonly logger : Logger ;
140
140
protected readonly shutdownSignalCallbacks = new Set < ( ) => void > ( ) ;
@@ -269,8 +269,6 @@ export class Runtime {
269
269
return ;
270
270
}
271
271
272
- const stopPollingForLogs = firstValueFrom ( this . stopPollingForLogs ) ;
273
-
274
272
const poll = promisify ( pollLogs ) ;
275
273
const doPoll = async ( ) => {
276
274
const logs = await poll ( this . native ) ;
@@ -286,14 +284,13 @@ export class Runtime {
286
284
for ( ; ; ) {
287
285
await doPoll ( ) ;
288
286
logger . flush ( ) ;
289
- const stop = await Promise . race ( [
290
- stopPollingForLogs . then ( ( ) => true ) ,
291
- new Promise < boolean > ( ( resolve ) => setTimeout ( ( ) => resolve ( false ) , 3 ) ) ,
292
- ] ) ;
293
- if ( stop ) {
294
- await doPoll ( ) ;
287
+ if ( this . stopPollingForLogs ) {
295
288
break ;
296
289
}
290
+ await new Promise < void > ( ( resolve ) => {
291
+ setTimeout ( resolve , 3 ) ;
292
+ this . stopPollingForLogsCallback = resolve ;
293
+ } ) ;
297
294
}
298
295
} catch ( error ) {
299
296
// Log using the original logger instead of buffering
@@ -479,7 +476,8 @@ export class Runtime {
479
476
public async shutdown ( ) : Promise < void > {
480
477
delete Runtime . _instance ;
481
478
this . teardownShutdownHook ( ) ;
482
- this . stopPollingForLogs . next ( ) ;
479
+ this . stopPollingForLogs = true ;
480
+ this . stopPollingForLogsCallback ?.( ) ;
483
481
// This will effectively drain all logs
484
482
await this . logPollPromise ;
485
483
await promisify ( runtimeShutdown ) ( this . native ) ;
0 commit comments