Overview

These are advanced types that you probably will never need to use.

Awaitable interfaces enable a type to be its own awaiter for performance reasons.

API

// An interface for an awaiter that does not return a result.
// This interface is intended to be implemented by a type which is its own awaiter for performance reasons.
public interface IAwaiter : INotifyCompletion
{
  // Gets a value indicating whether the awaiter completed synchronously.
  // This is only invoked once.
  bool IsCompleted { get; }

  // Gets the result of the awaiter (raising any exceptions if necessary).
  // This is only invoked once.
  // Generally, this should be explicitly implemented.
  void GetResult();
}

// An interface for an awaiter that returns a result.
// This interface is intended to be implemented by a type which is its own awaiter for performance reasons.
public interface IAwaiter<T> : INotifyCompletion
{
  // Gets a value indicating whether the awaiter completed synchronously.
  // This is only invoked once.
  bool IsCompleted { get; }

  // Gets the result of the awaiter (raising any exceptions if necessary).
  // This is only invoked once.
  // Generally, this should be explicitly implemented.
  T GetResult();
}

// An interface for an awaitable that does not return a result.
// This interface is intended to be explicitly implemented by a type which is its own awaitable for performance reasons.
public interface IAwaitable
{
  // Gets the awaiter.
  // Usually returns "this".
  // Generally, this should be explicitly implemented.
  IAwaiter GetAwaiter();
}

// An interface for an awaitable that returns a result.
// This interface is intended to be explicitly implemented by a type which is its own awaitable for performance reasons.
public interface IAwaitable<T>
{
  // Gets the awaiter.
  // Usually returns "this".
  // Generally, this should be explicitly implemented.
  IAwaiter<T> GetAwaiter();
}

// An interface for an awaitable/awaiter that does not return a result.
// This interface is intended to be implemented by a type which is its own awaitable and awaiter for performance reasons.
public interface IAwaitableAwaiter : IAwaitable, IAwaiter
{
}

// An interface for an awaitable/awaiter that returns a result.
// This interface is intended to be implemented by a type which is its own awaitable and awaiter for performance reasons.
public interface IAwaitableAwaiter<T> : IAwaitable<T>, IAwaiter<T>
{
}

Last edited Nov 17, 2012 at 2:26 PM by StephenCleary, version 1

Comments

No comments yet.