Skip to content

Commit 066599f

Browse files
committed
Merge pull request #359 from hoanhtien/fixQueueTimeout
Reduce queue timeout possibility.
2 parents 7705aca + 491530c commit 066599f

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

typescript/libs/node_client.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def sendCmdSync(self, cmd, seq):
119119
reqSeq = -1
120120
try:
121121
while reqSeq < seq:
122-
data = self.msgq.get(True, 1)
122+
data = self.msgq.get(True, 2)
123123
dict = json_helpers.decode(data)
124124
reqSeq = dict['request_seq']
125125
return dict
@@ -156,7 +156,8 @@ def getEvent(self):
156156
@staticmethod
157157
def read_msg(stream, msgq, eventq, asyncReq, proc, asyncEventHandlers):
158158
"""
159-
Reader thread helper
159+
Reader thread helper.
160+
Return True to indicate the wish to stop reading the next message.
160161
"""
161162
state = "init"
162163
body_length = 0
@@ -186,24 +187,21 @@ def read_msg(stream, msgq, eventq, asyncReq, proc, asyncEventHandlers):
186187
callback = asyncReq.pop(request_seq, None)
187188
if callback:
188189
callback(data_dict)
189-
return False
190190
else:
191191
# Only put in the queue if wasn't an async request
192192
msgq.put(data_json)
193193
elif data_dict["type"] == "event":
194194
event_name = data_dict["event"]
195195
if event_name in asyncEventHandlers:
196196
for cb in asyncEventHandlers[event_name]:
197-
if global_vars.IS_ST2:
198-
sublime.set_timeout(lambda: cb(data_dict), 0)
199-
else:
200-
cb(data_dict)
201-
return False
197+
# Run <cb> asynchronously to keep read_msg as small as possible
198+
sublime.set_timeout(lambda: cb(data_dict), 0)
202199
else:
203200
eventq.put(data_json)
204201
else:
205202
log.info('Body length of 0 in server stream')
206-
return False
203+
204+
return False
207205

208206
@staticmethod
209207
def which(program):

0 commit comments

Comments
 (0)