// 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 TaskCompletionSource
/// to simplify things
///
public class TaskStringVisitor : IStringVisitor
{
private readonly TaskCompletionSource taskCompletionSource;
///
/// Default constructor
///
public TaskStringVisitor()
{
taskCompletionSource = new TaskCompletionSource();
}
///
/// Method that will be executed.
///
/// string (result of async execution)
void IStringVisitor.Visit(string str)
{
taskCompletionSource.TrySetResultAsync(str);
}
///
/// Task that can be awaited for the result to be retrieved async
///
public Task Task
{
get { return taskCompletionSource.Task; }
}
void IDisposable.Dispose()
{
}
}
}