@@ -31,6 +31,7 @@ export class ClickHouse {
3131 public readonly reader : ClickhouseReader ;
3232 public readonly writer : ClickhouseWriter ;
3333 private readonly logger : Logger ;
34+ private _splitClients : boolean ;
3435
3536 constructor ( config : ClickHouseConfig ) {
3637 this . logger = config . logger ?? new Logger ( "ClickHouse" , "debug" ) ;
@@ -49,6 +50,8 @@ export class ClickHouse {
4950 } ) ;
5051 this . reader = client ;
5152 this . writer = client ;
53+
54+ this . _splitClients = false ;
5255 } else if ( config . writerUrl && config . readerUrl ) {
5356 this . reader = new ClickhouseClient ( {
5457 name : config . readerName ?? "clickhouse-reader" ,
@@ -62,9 +65,13 @@ export class ClickHouse {
6265 clickhouseSettings : config . clickhouseSettings ,
6366 logger : this . logger ,
6467 } ) ;
68+
69+ this . _splitClients = true ;
6570 } else {
6671 this . reader = new NoopClient ( ) ;
6772 this . writer = new NoopClient ( ) ;
73+
74+ this . _splitClients = true ;
6875 }
6976 }
7077
@@ -87,6 +94,14 @@ export class ClickHouse {
8794 } ) ;
8895 }
8996
97+ async close ( ) {
98+ if ( this . _splitClients ) {
99+ await Promise . all ( [ this . reader . close ( ) , this . writer . close ( ) ] ) ;
100+ } else {
101+ await this . reader . close ( ) ;
102+ }
103+ }
104+
90105 get taskRuns ( ) {
91106 return {
92107 insert : insertTaskRuns ( this . writer ) ,
0 commit comments