@@ -101,10 +101,10 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
101
101
102
102
constructor ( worker ?: Worker | SharedWorker | URL ) {
103
103
super ( worker )
104
- StateManager . on ( 'destroy' , ( ) => {
105
- if ( this . worker instanceof Worker )
106
- this . worker ?. terminate ( )
107
- } )
104
+ // StateManager.on('destroy', () => {
105
+ // if(this.worker instanceof Worker)
106
+ // this.worker?.terminate()
107
+ // })
108
108
}
109
109
110
110
get worker ( ) : Worker | SharedWorker | undefined {
@@ -131,30 +131,43 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
131
131
}
132
132
133
133
async unsubscribe ( hash ?: string ) : Promise < boolean > {
134
+ console . log ( 'WebsocketAdapter:unsubscribe' , hash )
134
135
if ( hash && ! this . subscriptions . has ( hash ) ) return true ;
136
+ console . log ( 'WebsocketAdapter:unsubscribe:found' , hash )
135
137
const unsub = this . request ( {
136
138
action : 'unsubscribe' ,
137
139
args : {
138
140
...defaultWebsocketRequestBody ,
139
- hash
141
+ hash,
142
+ options : {
143
+ ...defaultWebsocketAdapterOptions ,
144
+ returnResults : true
145
+ }
140
146
}
141
147
} )
148
+ console . log ( 'WebsocketAdapter:unsubscribe:sentrequest' , hash )
142
149
return this . response ( unsub ) as Promise < boolean >
143
150
}
144
151
145
152
async unsubscribeAll ( hash ?: string ) : Promise < boolean > {
146
153
const hashes = [ ...Array . from ( this . subscriptions ) ]
147
154
for ( let hash of hashes ) {
155
+ console . log ( 'WebsocketAdapter:unsubscribeAll' , hash )
148
156
await this . unsubscribe ( hash )
149
157
}
150
158
return true ;
151
159
}
152
160
153
161
async shutdown ( ) : Promise < void > {
154
- await this . unsubscribeAll ( ) ;
155
- await this . abort ( ) ;
156
- await delay ( 1000 ) ;
162
+ console . log ( 'WebsocketAdapter:shutdown' )
163
+ // console.log('WebsocketAdapter:shutdown:unsubscribing', this.subscriptions.size)
164
+ // await this.unsubscribeAll();
165
+ // console.log('WebsocketAdapter:shutdown:unsubscribed', this.subscriptions.size)
166
+ // await this.abort();
167
+ // console.log('WebsocketAdapter:shutdown:aborted')
168
+ // await delay(1000);
157
169
this . terminate ( )
170
+ console . log ( 'WebsocketAdapter:shutdown:terminated' )
158
171
await delay ( 100 ) ;
159
172
}
160
173
@@ -164,6 +177,10 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
164
177
args : {
165
178
...defaultWebsocketRequestBody ,
166
179
hash : 'abort' ,
180
+ options : {
181
+ ...defaultWebsocketAdapterOptions ,
182
+ returnResults : true
183
+ }
167
184
}
168
185
} )
169
186
return this . response ( abort ) as Promise < boolean >
@@ -239,12 +256,13 @@ export class WebsocketAdapter extends Adapter implements IWebsocketAdapter {
239
256
message . args . hash = deterministicHash ( message ?. args ?. filters ?? { } )
240
257
}
241
258
const { hash } = message . args
259
+ console . log ( 'WebsocketAdapter:request' , hash , message )
242
260
if ( ! this ?. worker ) {
243
261
console . warn ( '[WebsocketAdapter] Error sending command: no worker found' )
244
262
return hash
245
263
}
246
264
if ( this . worker instanceof Worker ) {
247
- // console.log('WebsocketAdapter:request', message)
265
+ console . log ( 'WebsocketAdapter:request' , message )
248
266
this . worker . postMessage ( message )
249
267
} else if ( this . worker instanceof SharedWorker )
250
268
this . worker . port . postMessage ( message )
0 commit comments