ToastPool.cs 623 B

12345678910111213141516171819202122232425
  1. using System.Collections.Concurrent;
  2. using SukiUI.Controls;
  3. using System.Collections.Generic;
  4. using SukiUI.Toasts;
  5. namespace SukiUI.Helpers;
  6. internal static class ToastPool
  7. {
  8. private static readonly ConcurrentBag<ISukiToast> Pool = new();
  9. internal static ISukiToast Get()
  10. {
  11. var toast = Pool.TryTake(out var item) ? item : new SukiToast();
  12. return toast.ResetToDefault();
  13. }
  14. internal static void Return(ISukiToast toast) => Pool.Add(toast);
  15. internal static void Return(IEnumerable<ISukiToast> toasts)
  16. {
  17. foreach (var toast in toasts)
  18. Pool.Add(toast);
  19. }
  20. }