Skip to content
Browse files

remoteCall has an optional keyword argument now named 'async'. Specif…

…y async=True in order to get an asynchronous result object you can use to get a result from your call. The default is synchronous (False), in which case you never get your result back, and any errors are shown to the user instead.

The appropriate functions now use async=True.
  • Loading branch information...
1 parent d2b981e commit 52e17cb173f5db74a963e5ad0622db09555298ac @kg committed
Showing with 22 additions and 14 deletions.
  1. +2 −0 Common/Common.cs
  2. +18 −12 Common/common.py
  3. +2 −2 Common/common.sql.py
View
2 Common/Common.cs
@@ -291,6 +291,8 @@ public Common (ScriptName name)
if (error != null) {
if (resultId.HasValue)
yield return SendRemoteCallResult(process, resultId.Value, null, error);
+ else
+ Program.Scheduler.OnTaskError(error);
} else {
resultTask = result as IEnumerator<object>;
View
30 Common/common.py
@@ -126,20 +126,26 @@ def _remoteCallComplete(resultId, result, errorText):
del _pendingRemoteCalls[resultId]
prc.set(result, errorText)
-def remoteCall(script, methodName, *args):
+def remoteCall(script, methodName, *args, **kwargs):
global _nextRemoteCallId, _pendingRemoteCalls
+
+ callData = [script, methodName, args]
+ result = None
+
+ if kwargs.get("async", False):
+ id = _nextRemoteCallId
+ _nextRemoteCallId += 1
- id = _nextRemoteCallId
- _nextRemoteCallId += 1
-
- stack = traceback.format_stack()
- rcr = RemoteCallResult(stack)
- _pendingRemoteCalls[id] = rcr
+ stack = traceback.format_stack()
+ result = RemoteCallResult(stack)
+ _pendingRemoteCalls[id] = result
+
+ callData.append(id)
channel = getChannel("remotecall")
- channel.send(json.dumps([script, methodName, args, id]))
+ channel.send(json.dumps(callData))
- return rcr
+ return result
def playSound(filename):
moduleName = getCallingModule()
@@ -153,14 +159,14 @@ def getPreference(name, moduleName=None):
moduleName = getCallingModule()
moduleName = moduleName.replace("shootblues.", "")
- return remoteCall(moduleName, "GetPreference", name)
+ return remoteCall(moduleName, "GetPreference", name, async=True)
def setPreference(name, value, moduleName=None):
if moduleName is None:
moduleName = getCallingModule()
moduleName = moduleName.replace("shootblues.", "")
- return remoteCall(moduleName, "SetPreference", name, value)
+ return remoteCall(moduleName, "SetPreference", name, value, async=True)
def showBalloonTip(title, text, timeout=None):
if timeout:
@@ -171,7 +177,7 @@ def showBalloonTip(title, text, timeout=None):
remoteCall("Common.Script.dll", "ShowBalloonTip", *args)
def showMessageBox(title, text, buttons="OK"):
- return remoteCall("Common.Script.dll", "ShowMessageBox", title, text, buttons)
+ return remoteCall("Common.Script.dll", "ShowMessageBox", title, text, buttons, async=True)
def onMainThread():
try:
View
4 Common/common.sql.py
@@ -1,7 +1,7 @@
from shootblues.common import log, remoteCall
def createTable(name, tableDef):
- return remoteCall("Common.Script.dll", "CreateDBTable", name, tableDef)
+ return remoteCall("Common.Script.dll", "CreateDBTable", name, tableDef, async=True)
def query(sql, *args):
- return remoteCall("Common.Script.dll", "ExecuteSQL", sql, *args)
+ return remoteCall("Common.Script.dll", "ExecuteSQL", sql, *args, async=True)

0 comments on commit 52e17cb

Please sign in to comment.
Something went wrong with that request. Please try again.