// Copyright © 2014 The CefSharp Authors. All rights reserved. // // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; using System.Threading.Tasks; using CefSharp.Internals; namespace CefSharp { /// /// A that uses a /// that allows you to call await/ContinueWith to get the result string. /// public class TaskStringVisitor : IStringVisitor { private readonly TaskCompletionSource taskCompletionSource; /// /// Initializes a new instance of the TaskStringVisitor class. /// public TaskStringVisitor() { taskCompletionSource = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); } /// /// Method that will be executed. /// /// string (result of async execution) void IStringVisitor.Visit(string str) { taskCompletionSource.TrySetResult(str); } /// /// Task that can be awaited for the result to be retrieved async /// public Task Task { get { return taskCompletionSource.Task; } } void IDisposable.Dispose() { } } }