using System;
using System.Threading;
using System.Threading.Tasks;
namespace Implab.Components {
///
/// Interface for the component which performs a long running task.
///
///
/// The access to the runnable component should be sequential, the
/// componet should support asynchronous completion of the initiated
/// operation but operations itself must be initiated sequentially.
///
public interface IRunnable {
///
/// Starts this instance
///
///
/// This operation is cancellable and it's expected to move to
/// the failed state or just ignore the cancellation request,
///
void Start(CancellationToken ct);
///
/// Stops this instance and releases all resources, after the
/// instance is stopped it is moved to Disposed state and
/// can't be reused.
///
///
/// If the componet was in the starting state the pending operation
/// will be requested to cancel. The stop operatin will be
/// performed only if the component in the running state.
///
void Stop(CancellationToken ct);
///
/// The result of the last started operation. This property reflects
/// only the result of the last started operation and therefore should
/// change only if a new operation is initiated.
///
Task Completion { get; }
///
/// Current state of the componenet
///
ExecutionState State { get; }
///
/// Event to monitor the state of the component.
///
event EventHandler StateChanged;
///
/// The last error
///
Exception LastError { get; }
}
}