def execute(cls, callback, **data):
"""Execute the given method remotely and call the callback with result
"""
def _start_worker(wk, cb, **d):
wk.start()
if wk.status == WorkerStatus.healthy:
wk._execute(cb, **d)
return
sublime.set_timeout_async(lambda: _start_worker(wk, cb, **d), 5000)
window_id = sublime.active_window().id()
worker = cls.get(cls, window_id)
if worker is None:
# hire a new worker
worker = cls.hire(cls)
cls.add(cls, window_id, worker)
if worker.status == WorkerStatus.faulty:
return
if worker.status == WorkerStatus.quiting:
cls.fire(cls, window_id)
return
if worker.client is not None:
if not worker.client.connected:
worker.reconnecting = True
worker.state = WorkerStatus.incomplete
_start_worker(worker, callback, **data)
else:
worker._append_context_data(data)
worker._execute(callback, **data)
if worker.status == WorkerStatus.quiting:
# that means that we need to let the worker go
cls.fire(cls, window_id)
else:
_start_worker(worker, callback, **data)
评论列表
文章目录