public async Task <IDescriptionPackage> LoadAsync(IContext ctx = default) { var ctxCt = ctx.Ct(); ctxCt.ThrowExceptionIfCancellationRequested(); var disposeCts = ReadDA(location: ref _disposeCts); var disposeCt = disposeCts.Token; var loader = ReadDA(location: ref _loader, considerDisposeRequest: true); var linkedCts = default(CancellationTokenSource); try { var linkedCt = CancellationTokenUtilities.SingleOrLinked(ct1: ctxCt, ct2: disposeCt, linkedCts: out linkedCts); using (var locCtx = ContextUtilities.Create(outerCtx: ctx, ct: linkedCt)) return(await loader.ExecuteAsync(ctx : locCtx).ConfigureAwait(false)); } finally { linkedCts?.Dispose(); } }
public async Task <REvaluationResult> EvaluateAsync(string expression, REvaluationKind kind, CancellationToken cancellationToken) { if (_runTask == null) { throw new InvalidOperationException("Host was not started"); } using (CancellationTokenUtilities.Link(ref cancellationToken, _cts.Token)) { try { await TaskUtilities.SwitchToBackgroundThread(); var request = await EvaluationRequest.SendAsync(this, expression, kind, cancellationToken); return(await request.Task); } catch (OperationCanceledException ex) when(_cts.IsCancellationRequested) { throw new RHostDisconnectedException(Resources.Error_RHostIsStopped, ex); } } }
public async Task <long> SetBlobSizeAsync(ulong blobId, long size, CancellationToken cancellationToken = default(CancellationToken)) { if (_runTask == null) { throw new InvalidOperationException("Host was not started"); } using (CancellationTokenUtilities.Link(ref cancellationToken, _cts.Token)) { try { await TaskUtilities.SwitchToBackgroundThread(); var request = await BlobSizeRequest.GetSizeAsync(this, blobId, cancellationToken); return(await request.Task); } catch (OperationCanceledException ex) when(_cts.IsCancellationRequested) { throw new RHostDisconnectedException(Resources.Error_RHostIsStopped, ex); } } }