internal void EndInvokeJS(long asyncHandle, bool succeeded, JSAsyncCallResult asyncCallResult) { using (asyncCallResult?.JsonDocument) { if (!_pendingTasks.TryRemove(asyncHandle, out var tcs)) { throw new ArgumentException($"There is no pending task with handle '{asyncHandle}'."); } if (succeeded) { var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs); try { var result = asyncCallResult != null? JsonSerializer.Deserialize(asyncCallResult.JsonElement.GetRawText(), resultType, JsonSerializerOptionsProvider.Options) : null; TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, result); } catch (Exception exception) { var message = $"An exception occurred executing JS interop: {exception.Message}. See InnerException for more details."; TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(message, exception)); } } else { var exceptionText = asyncCallResult?.JsonElement.ToString() ?? string.Empty; TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(exceptionText)); } } }
internal void EndInvokeJS(long asyncHandle, bool succeeded, JSAsyncCallResult asyncCallResult) { using (asyncCallResult?.JsonDocument) { if (!_pendingTasks.TryRemove(asyncHandle, out var tcs)) { throw new ArgumentException($"There is no pending task with handle '{asyncHandle}'."); } if (succeeded) { var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs); var result = asyncCallResult != null? JsonSerializer.Parse(asyncCallResult.JsonElement.GetRawText(), resultType, JsonSerializerOptionsProvider.Options) : null; TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, result); } else { var exceptionText = asyncCallResult?.JsonElement.ToString() ?? string.Empty; TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(exceptionText)); } } }
internal void EndInvokeJS(long asyncHandle, bool succeeded, object resultOrException) { if (!_pendingTasks.TryRemove(asyncHandle, out var tcs)) { throw new ArgumentException($"There is no pending task with handle '{asyncHandle}'."); } if (succeeded) { TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultOrException); } else { TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(resultOrException.ToString())); } }
internal void EndInvokeJS(long asyncHandle, bool succeeded, object resultOrException) { if (!_pendingTasks.TryRemove(asyncHandle, out var tcs)) { throw new ArgumentException($"There is no pending task with handle '{asyncHandle}'."); } if (succeeded) { var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs); var resultValue = resultOrException is SimpleJson.JsonObject ? ArgSerializerStrategy.DeserializeObject(resultOrException, resultType) : resultOrException; TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, resultValue); } else { TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(resultOrException.ToString())); } }
internal void EndInvokeJS(long taskId, bool succeeded, JSAsyncCallResult asyncCallResult) { using (asyncCallResult?.JsonDocument) { if (!_pendingTasks.TryRemove(taskId, out var tcs)) { // We should simply return if we can't find an id for the invocation. // This likely means that the method that initiated the call defined a timeout and stopped waiting. return; } CleanupTasksAndRegistrations(taskId); if (succeeded) { var resultType = TaskGenericsUtil.GetTaskCompletionSourceResultType(tcs); try { var result = asyncCallResult != null? JsonSerializer.Deserialize(asyncCallResult.JsonElement.GetRawText(), resultType, JsonSerializerOptionsProvider.Options) : null; TaskGenericsUtil.SetTaskCompletionSourceResult(tcs, result); } catch (Exception exception) { var message = $"An exception occurred executing JS interop: {exception.Message}. See InnerException for more details."; TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(message, exception)); } } else { var exceptionText = asyncCallResult?.JsonElement.ToString() ?? string.Empty; TaskGenericsUtil.SetTaskCompletionSourceException(tcs, new JSException(exceptionText)); } } }