Пример #1
0
        public async Task <bool> BeginEvaluationAsync(IReadOnlyList <IRContext> contexts, IRExpressionEvaluator evaluator, CancellationToken hostCancellationToken)
        {
            var evaluation = new RSessionEvaluation(contexts, evaluator, hostCancellationToken);

            if (_tcs.TrySetResult(evaluation))
            {
                await evaluation.Task;
            }
            return(evaluation.IsMutating);
        }
Пример #2
0
        public void TrySetResult() {
            var tcs = new TaskCompletionSourceEx<int>();
            var count = 0;
            ParallelTools.Invoke(8, i => {
                var isSet = tcs.TrySetResult(i);
                if (isSet) {
                    Interlocked.Increment(ref count);
                }
            });

            count.Should().Be(1);
        }
Пример #3
0
        public void TrySetResult()
        {
            var tcs   = new TaskCompletionSourceEx <int>();
            var count = 0;

            ParallelTools.Invoke(8, i => {
                var isSet = tcs.TrySetResult(i);
                if (isSet)
                {
                    Interlocked.Increment(ref count);
                }
            });

            count.Should().Be(1);
        }
Пример #4
0
        public void Request(IReadOnlyList <IRContext> contexts, string prompt, int maxLength, TaskCompletionSource <string> requestTcs)
        {
            var request = new RSessionInteraction(requestTcs, _responseTcs.Task, prompt, maxLength, contexts ?? new[] { RHost.TopLevelContext });

            if (_createRequestTcs.TrySetResult(request))
            {
                return;
            }

            request.Dispose();
            if (CreateRequestTask.IsCanceled)
            {
                throw new OperationCanceledException();
            }
        }
Пример #5
0
 private void SetResult(object state) => _tcs.TrySetResult((T)state);
Пример #6
0
 public void Dispose()
 {
     _hostCancellationRegistration.Dispose();
     _tcs.TrySetResult(null);
 }