You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// send initialization commands (will be enqued in the operations queue)
209
-
constcommands=this.initializationCommands
210
-
this.sendCommands(commands,error=>{
211
-
callback?.call(this,error)
212
-
})
213
-
214
208
returnthis
215
209
}
216
210
217
-
/** Will send a command and return the resulting rowset or result or throw an error */
218
-
publicsendCommands(commands: string,callback?: ResultsCallback): this {
219
-
this.operations.enqueue(done=>{
220
-
// connection needs to be established?
221
-
if(!this.socket){
222
-
callback?.call(this,newSQLiteCloudError('Connection not established',{errorCode: 'ERR_CONNECTION_NOT_ESTABLISHED'}))
223
-
return
224
-
}
211
+
/** Will send a command immediately (no queueing), return the rowset/result or throw an error */
212
+
privateprocessCommands(commands: string,callback?: ResultsCallback): this {
213
+
// connection needs to be established?
214
+
if(!this.socket){
215
+
callback?.call(this,newSQLiteCloudError('Connection not established',{errorCode: 'ERR_CONNECTION_NOT_ESTABLISHED'}))
216
+
returnthis
217
+
}
225
218
226
-
// compose commands following SCPC protocol
227
-
commands=formatCommand(commands)
219
+
// compose commands following SCPC protocol
220
+
commands=formatCommand(commands)
228
221
229
-
letbuffer=Buffer.alloc(0)
230
-
constrowsetChunks: Buffer[]=[]
231
-
conststartedOn=newDate()
232
-
this.log(`Send: ${commands}`)
222
+
letbuffer=Buffer.alloc(0)
223
+
constrowsetChunks: Buffer[]=[]
224
+
conststartedOn=newDate()
225
+
this.log(`Send: ${commands}`)
233
226
234
-
// define what to do if an answer does not arrive within the set timeout
235
-
letsocketTimeout: number
227
+
// define what to do if an answer does not arrive within the set timeout
228
+
letsocketTimeout: number
236
229
237
-
// clear all listeners and call done in the operations queue
238
-
constfinish: ResultsCallback=(error,result)=>{
239
-
clearTimeout(socketTimeout)
240
-
if(this.socket){
241
-
this.socket.removeAllListeners('data')
242
-
this.socket.removeAllListeners('error')
243
-
this.socket.removeAllListeners('close')
244
-
}
245
-
if(callback){
246
-
callback?.call(this,error,result)
247
-
callback=undefined
248
-
}
249
-
// process next operation in the queue
250
-
done?.call(this,error ? error : undefined)
230
+
// clear all listeners and call done in the operations queue
231
+
constfinish: ResultsCallback=(error,result)=>{
232
+
clearTimeout(socketTimeout)
233
+
if(this.socket){
234
+
this.socket.removeAllListeners('data')
235
+
this.socket.removeAllListeners('error')
236
+
this.socket.removeAllListeners('close')
251
237
}
238
+
if(callback){
239
+
callback?.call(this,error,result)
240
+
callback=undefined
241
+
}
242
+
}
252
243
253
-
// define the Promise that waits for the server response
254
-
constreadData=(data: Uint8Array)=>{
255
-
try{
256
-
// on first ondata event, dataType is read from data, on subsequent ondata event, is read from buffer that is the concatanations of data received on each ondata event
// need to decompress this buffer before decoding?
275
-
if(dataType===CMD_COMPRESSED){
276
-
;({ buffer, dataType }=decompressBuffer(buffer))
244
+
// define the Promise that waits for the server response
245
+
constreadData=(data: Uint8Array)=>{
246
+
try{
247
+
// on first ondata event, dataType is read from data, on subsequent ondata event, is read from buffer that is the concatanations of data received on each ondata event
0 commit comments