Пример #1
0
        protected async Task SendAsync(
            JupyterRequestContext context,
            IKernelCommand command)
        {
            command.SetToken(context.Token);

            var sub = Kernel.KernelEvents
                      .Where(e => e.Command?.GetToken() == context.Token)
                      .Subscribe(e => OnKernelEventReceived(e, context));

            await((KernelBase)Kernel).SendAsync(
                command,
                CancellationToken.None,
                onDone: () => sub.Dispose());
        }
Пример #2
0
        public static string GetToken(this IKernelCommand command)
        {
            if (command.Properties.TryGetValue(TokenKey, out var value) &&
                value is TokenSequence tokenSequence)
            {
                return(tokenSequence.Current);
            }

            if (command is KernelCommandBase commandBase &&
                commandBase.Parent != null)
            {
                var token = commandBase.Parent.GetToken();
                command.SetToken(token);
                return(token);
            }

            return(command.GenerateToken());
        }
Пример #3
0
        protected async Task SendAsync(
            JupyterRequestContext context,
            IKernelCommand command)
        {
            command.SetToken(context.Token);

            using var sub = Kernel
                            .KernelEvents
                            .Where(ShouldForward)
                            .Subscribe(e => OnKernelEventReceived(e, context));

            await((KernelBase)Kernel).SendAsync(
                command,
                CancellationToken.None);

            bool ShouldForward(IKernelEvent e)
            {
                return((e.Command?.GetToken() == context.Token) || e.Command.ShouldPublishInternalEvents());
            }
        }