Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

RemoteCall is slightly more efficient now, and errors don't spew to t…

…he error window since they're sent back to the python process
  • Loading branch information...
commit d2b981ef901e22d1af144f9f3a214aa69e38bb35 1 parent 10844df
@kg authored
Showing with 36 additions and 29 deletions.
  1. +36 −29 Common/Common.cs
View
65 Common/Common.cs
@@ -276,17 +276,42 @@ public Common (ScriptName name)
continue;
}
- var fResult = Start(process, RemoteCallInvoker(
- instance, methodName, functionArguments, rawArguments, serializer, scriptName, process
- ));
-
- if (resultId.HasValue) {
- fResult.RegisterOnComplete((_) => {
- object result;
- Exception error;
- _.GetResult(out result, out error);
- Start(process, SendRemoteCallResult(process, resultId.Value, result, error));
- });
+ IEnumerator<object> resultTask = null;
+ object result = null;
+ Exception error = null;
+
+ try {
+ result = instance.GetType().InvokeMember(
+ methodName, BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, instance, functionArguments
+ );
+ } catch (Exception ex) {
+ error = ex;
+ }
+
+ if (error != null) {
+ if (resultId.HasValue)
+ yield return SendRemoteCallResult(process, resultId.Value, null, error);
+ } else {
+ resultTask = result as IEnumerator<object>;
+
+ if (resultTask != null) {
+ var fResult = Program.Scheduler.Start(
+ resultTask, TaskExecutionPolicy.RunWhileFutureLives
+ );
+ process.OwnedFutures.Add(fResult);
+
+ if (resultId.HasValue) {
+ fResult.RegisterOnComplete((_) => {
+ object r;
+ Exception e;
+ _.GetResult(out r, out e);
+ Program.Scheduler.Start(SendRemoteCallResult(process, resultId.Value, r, e));
+ });
+ }
+ } else {
+ if (resultId.HasValue)
+ yield return SendRemoteCallResult(process, resultId.Value, result, null);
+ }
}
}
}
@@ -298,24 +323,6 @@ public Common (ScriptName name)
yield return Program.CallFunction(process, "common", "_remoteCallComplete", resultId, result, errorText);
}
- protected IEnumerator<object> RemoteCallInvoker (IManagedScript instance, string methodName, object[] functionArguments, object[] rawArguments, JavaScriptSerializer serializer, string scriptName, ProcessInfo process) {
- IEnumerator<object> resultTask = null;
- object result = null;
-
- result = instance.GetType().InvokeMember(
- methodName, BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public, null, instance, functionArguments
- );
- resultTask = result as IEnumerator<object>;
-
- if (resultTask != null) {
- var f = Start(process, resultTask);
- yield return f;
- yield return new Result(f.Result);
- } else {
- yield return new Result(result);
- }
- }
-
public void LoggedInCharacterChanged (ProcessInfo process, object characterName) {
process.Status = characterName as string ?? "Not Logged In";
Please sign in to comment.
Something went wrong with that request. Please try again.