IPromise.cs 1.0 KB

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) 2025 TerraByte Inc.
  2. //
  3. // Defines the public interface for a Promise, which represents the eventual
  4. // completion (or failure) of an asynchronous operation and its resulting value.
  5. // This decouples the consumer from the implementation.
  6. using System;
  7. namespace Terra.Arbitrator.Promises
  8. {
  9. public enum PromiseState { Pending, Resolved, Rejected }
  10. public interface IPromise<out TResult>
  11. {
  12. /// <summary>
  13. /// Attaches a callback that will execute when the promise is successfully resolved.
  14. /// </summary>
  15. IPromise<TResult> Then(Action<TResult> onResolved);
  16. /// <summary>
  17. /// Attaches a callback that will execute when the promise is rejected.
  18. /// </summary>
  19. IPromise<TResult> Catch(Action<Exception> onRejected);
  20. /// <summary>
  21. /// Attaches a callback that will execute when the promise is settled (either resolved or rejected).
  22. /// </summary>
  23. void Finally(Action onFinally);
  24. }
  25. }