private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken, CancellationToken ct) { try { if (!lockToken.IsSet) { await TaskUtilities.SwitchToBackgroundThread(); var stopwatch = new Stopwatch(); stopwatch.Start(); // Ensure session is started await _host.StartSessionAsync(ct); Debug.WriteLine("R function host start: {0} ms", stopwatch.ElapsedMilliseconds); // Fetch list of package functions from R session _disposableBag.ThrowIfDisposed(); stopwatch.Reset(); await LoadInstalledPackagesIndexAsync(ct); Debug.WriteLine("Fetch list of package functions from R session: {0} ms", stopwatch.ElapsedMilliseconds); // Try load missing functions from cache or explicitly _disposableBag.ThrowIfDisposed(); stopwatch.Reset(); await LoadRemainingPackagesFunctions(ct); Debug.WriteLine("Try load missing functions from cache or explicitly: {0} ms", stopwatch.ElapsedMilliseconds); // Build index _disposableBag.ThrowIfDisposed(); stopwatch.Reset(); await _functionIndex.BuildIndexAsync(this, ct); Debug.WriteLine("R function index build: {0} ms", stopwatch.ElapsedMilliseconds); stopwatch.Stop(); } } catch (RHostDisconnectedException ex) { Debug.WriteLine(ex.Message); ScheduleIdleTimeRebuild(); } catch (ObjectDisposedException) { } finally { lockToken.Set(); } }
private async Task StartHostAsyncBackground(RHost host, IBinaryAsyncLockToken lockToken, CancellationToken cancellationToken = default(CancellationToken)) { await TaskUtilities.SwitchToBackgroundThread(); ResetInitializationTcs(); ClearPendingRequests(new RHostDisconnectedException()); Interlocked.Exchange(ref _host, host); var initializationCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); var hostRunTask = RunHost(lockToken, initializationCts.Token); Interlocked.Exchange(ref _hostRunTask, hostRunTask)?.DoNotWait(); await _initializationTcs.Task; initializationCts.Dispose(); lockToken.Set(); }
private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken) { try { if (!lockToken.IsSet) { var startTotalTime = DateTime.Now; await TaskUtilities.SwitchToBackgroundThread(); await _host.StartSessionAsync(); Debug.WriteLine("R function host start: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds); var startTime = DateTime.Now; // Fetch list of available packages from R session await BuildInstalledPackagesIndexAsync(); Debug.WriteLine("R package names/description: {0} ms", (DateTime.Now - startTime).TotalMilliseconds); // Populate function index for preloaded packages first startTime = DateTime.Now; await BuildPreloadedPackagesFunctionListAsync(); Debug.WriteLine("R function index (preloaded): {0} ms", (DateTime.Now - startTime).TotalMilliseconds); // Populate function index for all remaining packages startTime = DateTime.Now; await BuildRemainingPackagesFunctionListAsync(); Debug.WriteLine("R function index (remaining): {0} ms", (DateTime.Now - startTime).TotalMilliseconds); await _functionIndex.BuildIndexAsync(this); Debug.WriteLine("R function index total: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds); } } catch (RHostDisconnectedException ex) { Debug.WriteLine(ex.Message); ScheduleIdleTimeRebuild(); } finally { lockToken.Set(); } }
private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken) { try { if (!lockToken.IsSet) { await TaskUtilities.SwitchToBackgroundThread(); var stopwatch = new Stopwatch(); stopwatch.Start(); // Ensure session is started await _host.StartSessionAsync(); Debug.WriteLine("R function host start: {0} ms", stopwatch.ElapsedMilliseconds); // Fetch list of package functions from R session await LoadInstalledPackagesIndexAsync(); Debug.WriteLine("Fetch list of package functions from R session: {0} ms", stopwatch.ElapsedMilliseconds); // Try load missing functions from cache or explicitly await LoadRemainingPackagesFunctions(); Debug.WriteLine("Try load missing functions from cache or explicitly: {0} ms", stopwatch.ElapsedMilliseconds); // Build index await _functionIndex.BuildIndexAsync(this); Debug.WriteLine("R function index total: {0} ms", stopwatch.ElapsedMilliseconds); stopwatch.Stop(); } } catch (Exception ex) when(!ex.IsCriticalException()) { Debug.WriteLine(ex.Message); ScheduleIdleTimeRebuild(); } finally { lockToken.Set(); } }
private async Task BuildIndexAsync(IBinaryAsyncLockToken lockToken) { try { if (!lockToken.IsSet) { var startTotalTime = DateTime.Now; await TaskUtilities.SwitchToBackgroundThread(); await _host.CreateSessionAsync(); Debug.WriteLine("R function host start: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds); var startTime = DateTime.Now; // Fetch list of available packages from R session await BuildInstalledPackagesIndexAsync(); Debug.WriteLine("R package names/description: {0} ms", (DateTime.Now - startTime).TotalMilliseconds); // Populate function index for preloaded packages first startTime = DateTime.Now; await BuildPreloadedPackagesFunctionListAsync(); Debug.WriteLine("R function index (preloaded): {0} ms", (DateTime.Now - startTime).TotalMilliseconds); // Populate function index for all remaining packages startTime = DateTime.Now; await BuildRemainingPackagesFunctionListAsync(); Debug.WriteLine("R function index (remaining): {0} ms", (DateTime.Now - startTime).TotalMilliseconds); await _functionIndex.BuildIndexAsync(this); Debug.WriteLine("R function index total: {0} ms", (DateTime.Now - startTotalTime).TotalMilliseconds); } } catch (RHostDisconnectedException ex) { Debug.WriteLine(ex.Message); ScheduleIdleTimeRebuild(); } finally { lockToken.Set(); } }