@@ -90,6 +90,19 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
9090 this . rpcSubscriptions = rpcSubscriptions ;
9191 }
9292
93+ private async handleNotificationLoop ( subscription : AsyncIterable < any > ) {
94+ for await ( const notification of subscription ) {
95+ if ( this . resubOpts ?. resubTimeoutMs ) {
96+ this . receivingData = true ;
97+ clearTimeout ( this . timeoutId ) ;
98+ this . handleRpcResponse ( notification . context , notification . value ) ;
99+ this . setTimeout ( ) ;
100+ } else {
101+ this . handleRpcResponse ( notification . context , notification . value ) ;
102+ }
103+ }
104+ }
105+
93106 async subscribe ( onChange : ( data : T ) => void ) : Promise < void > {
94107 if ( this . listenerId != null || this . isUnsubscribing ) {
95108 if ( this . resubOpts ?. logResubMessages ) {
@@ -109,6 +122,13 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
109122 const abortController = new AbortController ( ) ;
110123 this . abortController = abortController ;
111124
125+ this . listenerId = Math . random ( ) ; // Unique ID for logging purposes
126+
127+ if ( this . resubOpts ?. resubTimeoutMs ) {
128+ this . receivingData = true ;
129+ this . setTimeout ( ) ;
130+ }
131+
112132 // Subscribe to account changes using gill's rpcSubscriptions
113133 const pubkey = this . accountPublicKey . toBase58 ( ) ;
114134 if ( isAddress ( pubkey ) ) {
@@ -121,23 +141,8 @@ export class WebSocketAccountSubscriberV2<T> implements AccountSubscriber<T> {
121141 abortSignal : abortController . signal ,
122142 } ) ;
123143
124- for await ( const notification of subscription ) {
125- if ( this . resubOpts ?. resubTimeoutMs ) {
126- this . receivingData = true ;
127- clearTimeout ( this . timeoutId ) ;
128- this . handleRpcResponse ( notification . context , notification . value ) ;
129- this . setTimeout ( ) ;
130- } else {
131- this . handleRpcResponse ( notification . context , notification . value ) ;
132- }
133- }
134- }
135-
136- this . listenerId = Math . random ( ) ; // Unique ID for logging purposes
137-
138- if ( this . resubOpts ?. resubTimeoutMs ) {
139- this . receivingData = true ;
140- this . setTimeout ( ) ;
144+ // Start notification loop without awaiting
145+ this . handleNotificationLoop ( subscription ) ;
141146 }
142147 }
143148
0 commit comments