IAsync.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. namespace XGame.Framework.Asyncs
  3. {
  4. /// <summary>
  5. /// 异步完成回调方法
  6. /// </summary>
  7. /// <param name="aAsync"></param>
  8. public delegate void OnAsyncCompleted(IAsync aAsync);
  9. /// <summary>
  10. /// 异步核心接口
  11. /// </summary>
  12. public interface IAsync
  13. {
  14. /// <summary>
  15. /// 是否完成
  16. /// </summary>
  17. bool IsCompleted { get; }
  18. /// <summary>
  19. /// 进度
  20. /// </summary>
  21. float Progress { get; }
  22. /// <summary>
  23. /// 用户自定义对象
  24. /// </summary>
  25. object State { get; set; }
  26. /// <summary>
  27. /// 异常(如果发生)
  28. /// </summary>
  29. Exception Exception { get; }
  30. /// <summary>
  31. /// 异步完成的监听,
  32. /// 无论是否发生异常都会回调回来,
  33. /// 此版本回调会无序执行
  34. /// </summary>
  35. /// <param name="action"></param>
  36. /// <returns></returns>
  37. IAsync On(OnAsyncCompleted action);
  38. /// <summary>
  39. /// 异步完成的监听,
  40. /// 无论是否发生异常都会回调回来,
  41. /// listener会按order排序,数值越小越先执行, 小于0会先于回调函数版本执行
  42. /// </summary>
  43. /// <param name="listener"></param>
  44. /// <para name ="order"></para>
  45. /// <returns></returns>
  46. IAsync On(IAsyncListener listener, int order = 0);
  47. /// <summary>
  48. /// 移除监听
  49. /// </summary>
  50. /// <param name="action"></param>
  51. /// <returns></returns>
  52. IAsync RemoveOn(OnAsyncCompleted action);
  53. /// <summary>
  54. /// 移除监听
  55. /// </summary>
  56. /// <param name="listener"></param>
  57. /// <returns></returns>
  58. IAsync RemoveOn(IAsyncListener listener);
  59. /// <summary>
  60. /// 移除所有监听
  61. /// </summary>
  62. /// <returns></returns>
  63. IAsync RemoveAll();
  64. }
  65. }