public object WaitOnHandle(CallbackHandle handle) { if (handle.Resolved) { return(null); } if (!callbackDict.ContainsKey(handle.HandleId)) { throw new Exception("Engine error (report to developers). Cannot wait on invalid handle"); } #if DEBUG var callerMethod = (new System.Diagnostics.StackTrace()).GetFrame(1).GetMethod(); var callerName = (new System.Diagnostics.StackTrace()).GetFrame(1).GetMethod().Name; if (callerName == "SynchronousCall") { callerMethod = (new System.Diagnostics.StackTrace()).GetFrame(2).GetMethod(); } Console.WriteLine($"Waiting on handle {handle.HandleId}. Caller: {callerMethod.DeclaringType.Name}.{callerMethod.Name}"); #endif while (true) { GetMessage(out long requestId, out object result, out string error); if (requestId == handle.HandleId) { return(result); } // feature - add infinite loop check } }
private CallbackHandle RemoteCallInternal(Contract contract, object param, Func <object, string, object> callback) { long requestId = counter; counter++; var handle = new CallbackHandle(requestId, callback); callbackDict.Add(requestId, handle); SendMessage(param, "c_callfunc_" + contract.FuncName, requestId); return(handle); }