public override async Task <Kernel> CreateKernelAsync( SignalRConnectionOptions options, KernelInvocationContext context) { var connection = new HubConnectionBuilder() .WithUrl(options.HubUrl) .Build(); await connection.StartAsync(); await connection.SendAsync("connect"); var receiver = new KernelCommandAndEventSignalRHubConnectionReceiver(connection); var sender = new KernelCommandAndEventSignalRHubConnectionSender(connection); var proxyKernel = new ProxyKernel(options.KernelName, receiver, sender); var _ = proxyKernel.RunAsync(); proxyKernel.RegisterForDisposal(receiver); proxyKernel.RegisterForDisposal(async() => { await connection.DisposeAsync(); }); return(proxyKernel); }
private async Task <Kernel> CreateProxyKernel(Language language) { var psi = new ProcessStartInfo { FileName = "dotnet-interactive", Arguments = $"stdio --default-kernel {language.LanguageName()}", WorkingDirectory = Directory.GetCurrentDirectory(), RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, }; var process = new Process { StartInfo = psi }; TaskCompletionSource <bool> ready = new(); process.Start(); var receiver = new KernelCommandAndEventTextReceiver(process.StandardOutput); var sender = new KernelCommandAndEventTextStreamSender(process.StandardInput); var kernel = new ProxyKernel("proxy", receiver, sender); kernel.RegisterForDisposal(() => { process.Kill(true); process.Dispose(); }); var _ = kernel.RunAsync(); var sub = kernel.KernelEvents.OfType <KernelReady>().Subscribe(_ => { ready.SetResult(true); }); await ready.Task; sub.Dispose(); return(kernel); }