SharpRSS/SharpRss/Models/FeedModel.cs
2023-05-15 20:42:42 +02:00

35 lines
933 B
C#

using System.Threading.Tasks;
using CodeHollow.FeedReader;
namespace SharpRss.Models
{
public class FeedModel
{
public FeedModel(string rssUrl)
{
_rssUrl = rssUrl;
_fetchTask = FetchAsync();
}
private readonly Task _fetchTask;
public async Task FetchAsync() => _feed = await FeedCache.GetFeed(_rssUrl);
private Feed? _feed;
public Feed Base {
get
{
if (_feed == null)
{
if (_fetchTask.IsFaulted)
{ return new Feed(); }
if (_fetchTask.Status is not (TaskStatus.Running or TaskStatus.WaitingForActivation))
_fetchTask.Start();
_fetchTask.Wait();
}
return _feed ?? new Feed();
}
}
private readonly string _rssUrl;
}
}