Microsoft.R.StackTracing.RSessionExtensions.TracebackAsync C# (CSharp) Méthode

TracebackAsync() public static méthode

Retrieve the current call stack, in call order (i.e. the current active frame is last, the one that called it is second to last etc).
This method has snapshot semantics for the frames and their properties - that is, the returned collection is not going to change as code runs. However, calling various methods on the returned IRStackFrame objects, such as RStackFrameExtensions.DescribeChildrenAsync, will fetch fresh data, possibly from altogether different frames if the call stack has changed. Thus, it is inadvisable to retain the returned stack and use it at a later point - it should always be obtained anew at the point where it is used.
public static TracebackAsync ( this session, bool skipSourceFrames = true, CancellationToken cancellationToken = default(CancellationToken) ) : Task>
session this
skipSourceFrames bool /// If , excludes frames that belong to source() or rtvs:::debug_source() internal machinery at the bottom of the stack; /// the first reported frame will be the one with sourced code. ///
cancellationToken System.Threading.CancellationToken
Résultat Task>
        public static async Task<IReadOnlyList<IRStackFrame>> TracebackAsync(
            this IRSession session,
            bool skipSourceFrames = true,
            CancellationToken cancellationToken = default(CancellationToken)
        ) {
            await TaskUtilities.SwitchToBackgroundThread();

            var jFrames = await session.EvaluateAsync<JArray>("rtvs:::describe_traceback()", REvaluationKind.Normal, cancellationToken);
            Trace.Assert(jFrames.All(t => t is JObject), "rtvs:::describe_traceback(): array of objects expected.\n\n" + jFrames);

            var stackFrames = new List<RStackFrame>();

            RStackFrame lastFrame = null;
            int i = 0;
            foreach (JObject jFrame in jFrames) {
                lastFrame = new RStackFrame(session, i, lastFrame, jFrame);
                stackFrames.Add(lastFrame);
                ++i;
            }

            if (skipSourceFrames) {
                var firstFrame = stackFrames.FirstOrDefault();
                if (firstFrame != null && firstFrame.IsGlobal && firstFrame.Call != null) {
                    if (firstFrame.Call.StartsWith("source(") || firstFrame.Call.StartsWith("rtvs::debug_source(")) {
                        // Skip everything until the first frame that has a line number - that will be the sourced code.
                        stackFrames = stackFrames.SkipWhile(f => f.LineNumber == null).ToList();
                    }
                }
            }

            return stackFrames;
        }
    }
RSessionExtensions